-6

please help, i have json:

{"Alex":21,"Grek":34.4,"Mark":54.22}

I need convert this to Array or List How can I do that? Thanks you.

  • if you put your exact question into Google what happens? – Crowcoder Jun 19 '16 at 14:21
  • In google I only saw json type:[{Name:'John Simith',Age:35},{Name:'Pablo Perez',Age:34}] – Иван Иванов Jun 19 '16 at 14:23
  • Try this link i found using google http://stackoverflow.com/questions/9586585/convert-json-to-a-c-sharp-array – Joseph Jun 19 '16 at 14:24
  • 2
    Possible duplicate of [Deserialize JSON with C#](http://stackoverflow.com/questions/7895105/deserialize-json-with-c-sharp) – Johan B Jun 19 '16 at 14:30
  • I dont have name fore create class!! – Иван Иванов Jun 19 '16 at 14:31
  • Your JSON string is strange, probably you have to check how it is being generated in the first place and eventually fix that part. Anyway, the problem is that this JSON represents a single **object** with `Alex`, `Grek` and `Mark` **properties**. In order to deserialize it in array, you have to cast the result to `JObject` and build the list/array from properties, e.g. `var result = ((JObject)JsonConvert.DeserializeObject(YourString)).Properties().Select(p => new { p.Name, Value = (double)p.Value }).ToList();` – Ivan Stoev Jun 19 '16 at 16:32

1 Answers1

0

You have a json in the wrong format for an array, it should have square braces to represent an array, but it is still not enough. The name in the commas represent a property, and the value after semicolumn is the value of the property of the object you want to obtain from deserialize. Here you can find simple examples of json.

meJustAndrew
  • 6,011
  • 8
  • 50
  • 76