c# - How can I deserialize this json data with JSON.Net? -


i'm not sure how define data property deserialize following json data...

{ "response": {     "total_rows": 39,     "data": [       [         "xxxxxxxxxxxxxxxxxbs2vi",         "a7ac4aa7-7211-4116-be57-0c36fc2abeee",         "aaaaaa",         "crn burnley & victoria st",         "richmond",         "vic",         "3121",         "555-555-555",         null,         "real estate & home improvement > storage",         null,         null,         -37.8114511488511,         145.009782837163       ],       [ .. ]       [ .. ]       ....     },     status = "ok" } 

so had ..

public class resultdata {     public response response { get; set; }     public string status { get; set; } } 

and....

public class response {     public int total_rows { get; set; }     public ilist<string> data { get; set; } } 

but throwing exception, saying "can't cast float string". trying add last 2 floats, list<> .. failed.

how can fix this, please? (i can't control json output).

cheers :)

update

it looks content of data json property fixed size array fixed object types. there way define that, in .net code json.net knows how deserialize it? need make custom json deserializer json property?

if you're using .net 4.0 might consider using dynamic when dealing json.

i posted code shows 1 way of setting on question.

in example able do:

var serializer = new javascriptserializer(); serializer.registerconverters(new[] { new dynamicjsonconverter() });  dynamic obj = serializer.deserialize(json, typeof(object));  if (obj.status != "ok")     throw new oopsexception();  int rowcount = obj.total_rows;  foreach (var row in obj.data) {     string code1 = row[0];     string code2 = row[1];     string code3 = row[2];     string address = row[3];     string suburb = row[4];     string state = row[5];     string postcode = row[6];     string phone = row[7];     string something1 = row[8];     string name = row[9];     string something2 = row[10];     string something3 = row[11];     decimal longitude = row[12];     decimal latitude = row[13];      // todo use above values } 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -