0

I am trying to DeserializeObject but have not idea how to reach the object within the brackets []

            dynamic response = null;
        response = JsonConvert.DeserializeObject(apiResponseContent);
        apiResponseContent =
            "CasinoId: " + response.Result.FirstName + "\r\n" +
            "PlayerId: " + response.Result.Id

The response which I am trying to parse it:

"{\"Status\":{\"ErrorCode\":0,\"ErrorName\":\"SUCCEED\",\"ErrorMessage\":\"\",\"ReferenceNumber\":\"\"},\"Result\":[{\"FirstName\":Adam,\"Id\":6161999\"}]}"

Would appreciate as answer

Ran
  • 65
  • 1
  • 7

1 Answers1

1

I believe you can access fields in the JSON object using a key collection, so response["keynamehere"].

But the best way is to create an object that mimics the objects and fields of your JSON object, and then you can deserialize to that object and it will map the fields. (ie: JsonConvert.DeserializeObject<YOUROBJECTHERE>(apiResponseContent))

Please see some reference links on how to do that in more detail: http://www.newtonsoft.com/json/help/html/DeserializeObject.htm
Deserializing JSON data to C# using JSON.NET

If you want to get a bit more fancy, you can create your own custom converter: Deserialize the JSON where the values are field names with JSON.NET

Community
  • 1
  • 1
reverence12389
  • 457
  • 5
  • 15