How can I read this json on windows phone 8? -


i'm trying read following json in windows phone app using newtonsoft.json

i can't read anything. looks pretty strange me.

{"type": "menu","menu": [{"0":"antipasto","tipo_piatto":"antipasto","1":"porchetta","nome_piatto":"porchetta","2":"1","prezzo":"1"}, {"0":"primo","tipo_piatto":"primo","1":"matriciana","nome_piatto":"matriciana","2":"5","prezzo":"5"}, {"0":"secondo","tipo_piatto":"secondo","1":"salsicce","nome_piatto":"salsicce","2":"4","prezzo":"4"}, {"0":"contorno","tipo_piatto":"contorno","1":"patate","nome_piatto":"patate","2":"2","prezzo":"2"}, {"0":"dolce","tipo_piatto":"dolce","1":"gelato","nome_piatto":"gelato","2":"6","prezzo":"6"}]}

this c# code now

 public class piatto_menu_giorno     {         public string tipo_piatto { get; set; }         public string nome_piatto { get; set; }         public string prezzo { get; set; }      }      public menu()     {         initializecomponent();          webclient webclient = new webclient();         uri uri = new uri("http://www.stepapp.it/areacli/extdevice/getmenuodierno_101.php");         webclient.openreadcompleted += new openreadcompletedeventhandler(fine_lettura_web);         webclient.openreadasync(uri);     }      private void fine_lettura_web(object sender, openreadcompletedeventargs e)     {         datacontractjsonserializer json = null;         json = new datacontractjsonserializer(typeof(observablecollection<piatto_menu_giorno>));         observablecollection<piatto_menu_giorno> menu = json.readobject(e.result) observablecollection<piatto_menu_giorno>;         if(menu==null)             menu_giorno.text = "null";         else         foreach (piatto_menu_giorno piatto in menu)         {                 menu_giorno.text += piatto.nome_piatto + "\n";         }     } 

sorry variables name in italian

i writing code you deserialize object json yourclasscustomobject.

private async task<list<piatto_menu_giorno>> mydeserializerfunasync() {     list<piatto_menu_giorno> book = new list<piatto_menu_giorno>();     try     {        //i taking url appsettings. mykey appsetting key. can write direct url.        string url = (string)appsettings["mykey"];        var request = httpwebrequest.create(url) httpwebrequest;        request.accept = "application/json;odata=verbose";        var factory = new taskfactory();        var task = factory.fromasync<webresponse>(request.begingetresponse,request.endgetresponse, null);        var response = await task;        stream responsestream = response.getresponsestream();        string data;        using (var reader = new system.io.streamreader(responsestream))        {            data = reader.readtoend();        }        responsestream.close();        datacontractjsonserializer json = new datacontractjsonserializer(typeof(list<piatto_menu_giorno>));        memorystream ms = new memorystream(encoding.utf8.getbytes(data));        book = (list<piatto_menu_giorno>)json.readobject(ms);        return book;    } }  

above code working in wp8 application faster can try, you. performing asynchronous operation can create simple method piatto_menu_giorno return type.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -