EDIT: Updated JSON string to valid JSON I am trying to convert a JSON string to preferably a class in c# using fastJSON.
This is my string (I cut everything out so only thing left is what I have trouble with)
{
"apps": {
"App Name 1": {
"label": "AppNam1",
"versions": [
{
"app_version": "4.7",
"application": "appname1"
}
]
},
"App Name 2": {
"label": "App Name 2",
"versions": [
{
"app_version": "1.0",
"application": "appname2"
}
]
}
}
}
Now, using fastJSON I am trying to convert this to the following model:
[Serializable()]
public class AppsRoot
{
public List<AppDetail> apps;
}
[Serializable()]
public class AppDetail{
public string label;
public List<AppVersions> versions;
}
However, this does not work for a couple reasons (at least, that's why I think it is not working): - First of all, the apps : {} contains a list of apps. However, fastJSON does not see this as a list. Probably because there have to be brackets around it in order to be a list? (like it is for versions) - Secondly, the AppName1 and AppName2 are dynamic keys. How can I make fastJSON assign this to an attribute somehow, if that is even possible?
This is the code I execute:
fastJSON.JSON.ToObject<AppsRoot>(myjsonstring)
It just returns an empty AppsRoot object.
FYI: if I just take the JSON for a single App containing a label and do this:
fastJSON.JSON.ToObject<AppDetail>(myjsonstring-part)
Then it does work. I returns the AppDetail with a list of versions.
Hopefully someone can help me out. The reason I am using fastJSON is because of performance btw, but I am open to alternatives.