0

I have incoming JSON formatted like this:

{
    "users": [
        {
            "radio_id": "123582",
            "callsign": "ABCD",
            "name": "First Last",
            "city": "Dortmund",
            "state": "Nordrhein-Westfalen",
            "country": "Germany",
            "home_rptr": "W2VL",
            "remarks": "None"
        },
        {
            "radio_id": "789456",
            "callsign": "EFG",
            "name": "Name Here",
            "city": "Dortmund",
            "state": "Nordrhein-Westfalen",
            "country": "Germany",
            "home_rptr": "W2VL",
            "remarks": "None"
        }
    ]
}

It is coming from a web request that I catch into a string called dataReceived. I then use this line of code to convert to a datatable.

DataTable dtData = (DataTable)JsonConvert.DeserializeObject(dataReceived, (typeof(DataTable)));

I'm getting an error of: Unexpected JSON token when reading DataTable. Expected StartArray, got StartObject. Path '', line 1, position 1.

I suspect my problem is the data is in an array, but I'm not sure how to solve this. My objective is to have a table with each row one of the "users" objects in the json.

Can anyone push me in the right direction?

Bernie Hunt
  • 306
  • 4
  • 22
  • can you try converting using deserialize http://stackoverflow.com/questions/25782765/newtonsoft-json-jsonconvert-to-datatable – Krishna Jul 21 '15 at 14:21

1 Answers1

2
var dt = JObject.Parse(json)["users"].ToObject<DataTable>();

That is all.

EZI
  • 15,209
  • 2
  • 27
  • 33