Deserialize JSON with the following format [param 1, param 2, param 3]

0

How can I deserialize this information.

{"games":"[
[ID, Descripcion1, Descripcion2, Descripcion3],
[222, Halo,      $2333, null],
[333, Sugar,    $333, null]]}
"
    
asked by user102063 02.10.2018 в 13:42
source

1 answer

0

You can not because it is badly formed, in several aspects, one of them is that you have some quotes right after "games":

{
  "games":
    "[
        [ID, Descripcion1, Descripcion2, Descripcion3],
        [
          222, Halo,$2333, null
        ],
        [
          333, Sugar, $333, null]
     ]
}

Once the solutions, there is more to be done anyway, since that object is not a valid JSON object. You should expose it like this

{
    "games": [
        {
            "Id": "222",
            "Descripcion1": "Halo",
            "Descripcion2": "$2333",
            "Descripcion3": null
        },
        {
            "Id": "333",
            "Descripcion1": "Sugar",
            "Descripcion2": "$333",
            "Descripcion3": null
        }
    ]
}

And being that way you could deserialize it in objects of these classes

public class Game
{
    public string Id { get; set; }
    public string Descripcion1 { get; set; }
    public string Descripcion2 { get; set; }
    public object Descripcion3 { get; set; }
}

public class RootObject
{
    public List<Game> games { get; set; }
}

Using Newtonsoft JSON

RootObject g = JsonConvert.DeserializeObject<RootObject>(json);
    
answered by 02.10.2018 в 18:16