I am unable to deserialize my Json String with the help of "DataContractJsonSerializer". I can't use third party tool for deserialization, my json string has no any enter code here
MainObject so i am unable to do, Please help me. My json data is below.
[{
"id": "2348",
"fo": "",
"na": "og",
"ex": "",
"ge": "",
"no_cl": "Phr",
"wo_cl": {
"id": "27",
"na": "kon",
"na_cl": "WordClass"
},
"con": []
}]
my classes according to above Json is following.
public class WoCl
{
public string id { get; set; }
public string na { get; set; }
public string na_cl { get; set; }
}
public class RootObject
{
public string id { get; set; }
public string fo { get; set; }
public string na { get; set; }
public string ex { get; set; }
public string ge { get; set; }
public string no_cl { get; set; }
public WoCl wo_cl { get; set; }
public List<object> con { get; set; }
}
My deserializing code is following.
string json = returnDictionaryJsonFromServer();//this function returning above json data
List<MainObject> obj = new List<MainObject>();
var memoryStream = new MemoryStream(Encoding.Unicode.GetBytes(json));
var serializer = new DataContractJsonSerializer(obj.GetType());
obj = serializer.ReadObject(memoryStream) as List<MainObject>;
return obj;