-2

How parse this Json in C#, I tried use JsonConvert.DeserializeObject, but I suppose my Class does not suitable for JsonConvert.

I am receiving response in Json and it is looks like this:

"{"response":[{"id5":[1,43,42]},{"id22":[7,9,10,3]}]}"

or

 "
        {
          "response":
            [
               {"id5":[1,43,42]},
               {"id22":[7,9,10,3]}
            ]
        }
"

Update/Solved: I am bad familiar with json, and I have task to generate some request and answer format depends on my request string.. so my request string was wrong generated and I received invalid Json.

Correct generation:

sb.Append("return [");
            foreach (string id in ids)
            {
                string q = "{\"id\" : " + id + ", \"friends\": :API.friends.get({user_id:" + id + "})}";
                sb.Append(q);
                sb.Append(',');
            }
            sb[sb.Length - 1] = ']';
            sb.Append(';');
d40a
  • 154
  • 9

3 Answers3

0

Have you look at Json class? https://msdn.microsoft.com/en-us/library/windows/apps/br229889.aspx

You would need just something like this (did not compiled):

JsonObject obj = JsonObject.Parse(your_resonse_string);
IJsonValue siri = ParseJsonObject(obj, "response");
JsonArray ids= VehicleMonitoringDelivery.GetArray();
foreach (var id in ids)
{
     (...)
}
CCamilo
  • 897
  • 1
  • 15
  • 18
0

You can use this class to deserialize your json

public class MyResponse
{
    public List<Dictionary<string,List<int?>>> response { get; set; }
}

Now your code would be

var obj = JsonConvert.DeserializeObject<MyResponse>(json);
Eser
  • 12,346
  • 1
  • 22
  • 32
-1

It would be hard to represent this JSON like class.

It looks like it has been generated in wrong way.

If you could change generating, better to do it in such way:

"
    {
      "response":
        [
           {"id":"id5","array":[1,43,42]},
           {"id":"id22":,"array":[7,9,10,3]}
        ]
    }
"

P.S. I have added "id" and "array"

If it is hard to make class manually, try this.

M0sTik
  • 1
  • 1
  • 3