0

Hi guys I'm new to this.

how would you deserialize json with this structure?

{
"0":{"name":"Simon"},
"1":{"name":"Les"},
"2":{"name":"Brian"}
"status_code":"1"
}

I already tried using JavaScriptSerializer().Deserialize(result); but it doesn't work.

any help is greatly appreciated

Thanks!

  • the popular NewtonSoft.Json will probably work. https://www.nuget.org/packages/Newtonsoft.Json/ – mtbnunu Aug 18 '17 at 07:48
  • 3
    Possible duplicate of [Deserialize JSON with C#](https://stackoverflow.com/questions/7895105/deserialize-json-with-c-sharp) – Samuil Petrov Aug 18 '17 at 07:54
  • hi @mtbnunu I tried to use NewtonSoft.Json,JsonConvert.DeserializeObject(); – rafael reyes Aug 18 '17 at 08:15
  • @mtbnunu I tried your suggestion I used Newton.Json.JsonConvert().DeserializeObject(); But how can I access the Property of Object "0"? dynamic r = Newtonsoft.Json.JsonConvert.DeserializeObject(responseData); – rafael reyes Aug 18 '17 at 08:18
  • I'm a bit rusty, but I remember it changes special variable names to something else, probably _0, I would suggest stepping through to test your result variable. Also, if you know the structure of the json then you can deserialize it into class, making it easier to use. https://www.newtonsoft.com/json/help/html/DeserializeObject.htm – mtbnunu Aug 18 '17 at 08:32

1 Answers1

-2

JSON.parse().

var arr_from_json = JSON.parse( json_string );

In browsers that don't, you can include the json2 library.

Kenpachi
  • 107
  • 9