Answer the question
In order to leave comments, you need to log in
how to deserialize such json in c#
{"response":[64,{"pid":"114272714","aid":"33565378",
"owner_id":"5005272","created":"1214309659","text":"test",
"src":"http:\/\/cs1437.vkontakte.ru\/u5005272\/33565378\/m_2a07b7cb.jpg",
"src_big":"http:\/\/cs1437.vkontakte.ru\/u5005272\/33565378\/x_5769a2b7.jpg",
"src_small":"http:\/\/cs1437.vkontakte.ru\/u5005272\/33565378\/s_beb1d458.jpg"}]}
public class UserPhotos
{
public Int32 pid { get; set; }
public Int32 aid { get; set; }
public Int32 owner_id { get; set; }
public Int32 created { get; set; }
public string text { get; set; }
public string src { get; set; }
public string src_big { get; set; }
public string src_small { get; set; }
}
public class vkUserPhotos
{
public List response { get; set; }
}
сейчас я вырезаю первый элемент, и десеареилизую в такую штуку
System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
string oList = oSerializer.Deserialize(json);
Answer the question
In order to leave comments, you need to log in
Why reinvent the wheel?
msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx
Why serialize a string? Sealing after all means translation of objects in a line.
Try james.newtonking.com/projects/json-net.aspx Have
used it a few times already and it seems to be pretty good :)
Here is a primitive json decoder (even two), carefully coded, but well commented, written in order not to carry heavy 'correct' json projects with me (plus it does not require new versions of .net, It will work almost with 1.1, incl. h. mono), requires additional processing of syntax errors, etc. (read todo: in comments).
pastebin.com/5jJsVs39
First method SimpleJSON::pairsParseJSON(string) - returns a single-level Dictionary<string, string>, each entry is leaf elements in the json tree, keys are a compound name of the elements separated by a dot (arrays are named through '[index] '), For example:
{test:[{a:1,b:'asd'},123]}
"test[0].a" => "1"ps this method is very handy when dealing with complex json structures without arrays
"test[0].b" => "asd"
"test[1]" => "123"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question