Reputation: 96
I get the following JSON data from JSON endpoint API's which I can't change:
[
[
"NameA",
[
"AAA"
]
],
[
"NameB",
[
"BBB"
]
],
[
"NameC",
[
"CCC"
]
]
]
I know its a valid JSON. Though I am not able to parse it in C#. I tried to generate the class for this JSON using online tools but it did not help. Any help would be appreciated as I'm really stuck on this.
Upvotes: 1
Views: 601
Reputation: 2809
You can use MessagePack via Nuget.
CLASS OBJECTS
[MessagePackObject]
public class Item1
{
[Key(0)]
public string Key { get; set; }
[Key(1)]
public Item2 Value { get; set; }
}
[MessagePackObject]
public class Item2
{
[Key(0)]
public string Value { get; set; }
}
SERIALIZATION
var json = File.ReadAllText("json1.json");
var byteArray = MessagePackSerializer.ConvertFromJson(json);
var itemList = MessagePackSerializer.Deserialize<List<Item1>>(byteArray);
Upvotes: 2