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

Feb 19, 2011 at 11:37 PM

Hi folks,

JSON.NET is throwing an exception when I'm trying to parse the following json. It's saying it can't convert a float to a string. (which is correct, actually). I'm not sure how to change my c# class to properly accomodate the json OR create some special json class so it knows how to deserialize the json.

here's the json...

 

{
"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"
}

 

It errors when it's trying to deserialize the data property of the json.

I've tried to do the following c# code..

 

public class ResultData
{
    public Response Response { get; set; }
    public string Version { get; set; }
    public string Status { get; set; }
}
public class Response
{
    public List<string> Data { get; set; } // <-- this is the original exception getting thrown.

    // The rest are snipped...
}
or
public class Response
{
    public List<object> Data { get; set; }

    // The rest are snipped...
}

 

or

public class Response
{
    public List<List<object>> Data { get; set; }

    // The rest are snipped...
}

It's because the json data field is a mixed bag .. but it's a fixed size and each array slot is also a fixed type .. but I don't know how to define that in my .NET code.

any suggestions?