Json Deserialization

Posted by Patil_Rakesh under C# on 9/11/2013 | Points: 10 | Views : 1291 | Status : [Member] | Replies : 5
HI,
Please help me to deserialize this json into list

Note: this json has dyanamic object names

json :
.
.
"http://d.abc.com/genericHasher-1/bb662ed1-6f4d-3a29-a837-8637cd479d4c": {
"_typeGroup": "entities",
"_type": "Position",
"name": "co-founder",
"_typeReference": "http://s.opencalais.com/1/type/em/e/Position",
"relevance": 0.312
},
"http://d.abc.com/comphash-1/3b1045e3-d1d7-3505-81a3-3cbe045bbbd7": {
"_typeGroup": "entities",
"_type": "Company",
"name": "Amazon",
"nationality": "N/A",
"_typeReference": "http://s.opencalais.com/1/type/em/e/Company",
"relevance": 0.158
},
.
.


Class :

public class Calais_Entity
{
[JsonProperty]
[DataMember(Name = "_typeGroup")]
public string _typeGroup { get; set; }

[JsonProperty]
[DataMember(Name = "_type"]
public string _type { get; set; }

[JsonProperty]
[DataMember(Name = "name")]
public string name { get; set; }

[JsonProperty]
[DataMember(Name = "nationality")]
public string nationality { get; set; }

[JsonProperty]
[DataMember(Name = "relevance")]
public string relevance { get; set; }

}




Responses

Posted by: Nismeh on: 9/11/2013 [Member] Starter | Points: 25

Up
0
Down
Hi,

http://www.codeproject.com/Tips/210810/Deserialize-JSON-with-C



IT KNOWLEDGE IS APPLIED KNOWLEDGE
So Just Do It

Patil_Rakesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 9/11/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Refer
http://www.codeproject.com/Tips/79435/Deserialize-JSON-with-C
http://computerbeacon.net/blog/deserializing-json-data-in-c

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Patil_Rakesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 9/11/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Dear Patil_Rakesh,

Here you need to store the Json values to string variable.
Then you need to use the below code:-

var s = new System.Web.Script.Serialization.JavaScriptSerializer();

string val = "[{name:\"Alex\", age:\"34\"}, {name:\"Code\", age:\"55\", size:180}]";
Object obj = s.DeserializeObject(val);


Another Way
This one is much smarter. It will convert each item into the passed object and return a List.
var s = new System.Web.Script.Serialization.JavaScriptSerializer();

List<myObject> obj = s.Deserialize<List<myObject>>


public class myObject

{
public string name { get; set; }
public int age { get; set; }
}


Happy Coding.

If it helps you or directs U towards the solution, MARK IT AS ANSWER

Patil_Rakesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Patil_Rakesh on: 9/12/2013 [Member] Starter | Points: 25

Up
0
Down
Thank you frnds..,
but i wasnt looking for single object. finally i got solution from :
http://stackoverflow.com/questions/7672182/c-sharp-how-to-translate-json-data-into-an-objects


Patil_Rakesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 9/12/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Thanks for posting solution link...

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Patil_Rakesh, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response