Sunday, 15 March 2015

c# - How do I deserialise this JSON? -


I have not done anything with JSON before ... so I'm probably losing a step.

Here is an example of JSON which I want to deserialise:

  {"item": {"icon": "http://services.runescape.com / M = itemdb_rs / 4765_obj_sprite? .gif id = 4798 "," icon_large ":" http://services.runescape.com/m=itemdb_rs/4765_obj_big.gif?id=4798 "," id ": 4798," type ":" Ammo "," typing icon ":" http://www.runescape.com/img/categories/Ammo "," name ":" Admitted Cruel "," Description ":" Blunt Adm. Arrow ... Ouch "" "{" Trend ":" neutral "," price ": 237}," today ": {" trend ":" neutral "," price ": 0}," members ":" true ", "Day30": {"trend": "positive", "change": "+ 1.0%"}, "day90": {"trend": " "Positive", "change": "+ 0.0%"}}}  

"", "change": "positive", "change": "- 0.0%"}, "day180" I put it in "Jason 2C #" and finished building this new .ccs file:

 using the  system; Using System.Collections.Generic; Using System.Linq; Using System.Text; System usage threading. Task; Namespace RST ool.Models {Receive {public class current {public string trend; Set; } Public Interval Value {Received; Set; }} Public square today {public string trend {get; Set; } Public Interval Value {Received; Set; }} Public Season Day 30 {public string trend {get; Set; } Public string change {get; Set; }} Public Square Day90 {public string trend {get; Set; } Public string change {get; Set; }} Public square Day180 {public string trend {get; Set; } Public string change {get; Set; }} Public square item {public string icon {get; Set; } Public string icon_large {get; Set; } Receive public ID { Set; } Public string type {get; Set; } Public String Type Icon {get; Set; } The name of the public string {get; Set; } Public string description {get; Set; } Current public current {get; Set; } Public today {received; Set; } Receive public string members { Set; } Public Day 30 Day 30 {Received; Set; } Public Day90 day90 {get; Set; } Public Day180 day180 {get; Set; }} Public class root object {public item items {received; Set; }}}  

So, I have the class. I can get JSON as a string from its place, but I do not know how to delete it. I have installed the Newtons Jason and have tried to use the populate object and deserlaiyzer but not with any luck ...

assuming that my JSON is a string called "json" Is stored in the form, that quay How would you know about archiving and then retrieving the item name, for example?

; RootObject & gt; (JSON);

I have successfully tested the code provided by you.

You can then access the property's properties in general:

  MessageBox.Show (deserialized.item.name);  

No comments:

Post a Comment