1

I'm trying to parse a nested JSON string returned from the GCM (Google Could Messaging) server using VB.NET. The JSON string looks like this:

{ "multicast_id": 216,
  "success": 3,
  "failure": 3,
  "canonical_ids": 1,
  "results": [
    { "message_id": "1:0408" },
    { "error": "Unavailable" },
    { "error": "InvalidRegistration" },
    { "message_id": "1:1516" },
    { "message_id": "1:2342", "registration_id": "32" },
    { "error": "NotRegistered"}
  ]
}

I would like to get the results array in the above string.

I found the following example helpful, example but it does not show how to get to the nested parts, specifically message_id, error and registration_id inside the results array.

Thanks

1 Answer 1

4

I'll give an answer using c# and Json.net

var jobj = JsonConvert.DeserializeObject<Response>(json);

You can also use JavaScriptSerializer

var jobj2 = new JavaScriptSerializer().Deserialize<Response>(json);

public class Result
{
    public string message_id { get; set; }
    public string error { get; set; }
    public string registration_id { get; set; }
}

public class Response
{
    public int multicast_id { get; set; }
    public int success { get; set; }
    public int failure { get; set; }
    public int canonical_ids { get; set; }
    public List<Result> results { get; set; }
}
Sign up to request clarification or add additional context in comments.

2 Comments

@KashifB use Telerik's Code Converter to translate the C# to VB.NET
Multicast Id and others should be long - int is too small for what google sends back

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.