c# - How to parse this String using System.Runtime.Serialization.Json? -


can me how use system.runtime.serialization.json (not json.net) information of each book in tring array:

{     "books":     [         {"name":"book 1","orig":"author 1","date":2009,"lang":"en"},         {"name":"book 2","orig":"author 2","date":2012,"lang":"fr"}     ],     "src":"lib",     "id":212 } 

here's quick sample whipped appears work:

using system; using system.collections.generic; using system.io; using system.runtime.serialization; using system.runtime.serialization.json;  class test {     static void main()     {         using (stream stream = file.openread("test.json"))         {             var serializer = new datacontractjsonserializer(typeof(library));             library library = (library) serializer.readobject(stream);             console.writeline(library.books[0].name);         }      } }  [datacontract] class book {     [datamember(name="name")] public string name { get; set; }     [datamember(name="orig")] public string orig { get; set; }     [datamember(name="date")] public string date { get; set; }     [datamember(name="lang")] public string lang { get; set; } }  [datacontract] class library {     [datamember(name="books")] public ilist<book> books { get; set; }     [datamember(name="src")] public string src { get; set; }     [datamember(name="id")] public string id { get; set; } } 

i'm sure there plenty of other options can tweak, should @ least started.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -