I am getting error while deserializing jsonString.
Error is Type 'oodleListingsUser' is not supported for deserialization of an array.
My code of deserialization is
string jsonString = new WebClient().DownloadString("http://api.oodle.com/api/v2/listings?key=TEST®ion=region_value&category=category_value&format=json");
JavaScriptSerializer ser = new JavaScriptSerializer();
jsonOodleApi p = ser.Deserialize<jsonOodleApi>(jsonString);
My class defination of jsonOodleApi is
public class jsonOodleApi
{
public oodleCurrent current;
public oodleListings[] listings;
public oodleMeta meta;
public string state { get; set; }
}
Defination of oodleCurrent and oodleMeta I am not giving because its perfect !
Defination of oodleListings is
public class oodleListings
{
public string id { get; set; }
public string title { get; set; }
public oodleListingsUser user;
// I have skipped some of fields because it have no issue at all.
}
Defination of oodleListingsUser is
public class oodleListingsUser
{
public string id { get; set; }
public string url { get; set; }
public string name { get; set; }
public string photo { get; set; }
}
The problem is my jsonString sometimes returns only one value of user (type of oodleListingsUser), and sometimes it returns array of user, and sometimes it returns null of user !
When it returns only one user, it runs perfectly fine ! No issue.
But when it returns array of user, bloom ! error occurs Type 'oodleListingsUser' is not supported for deserialization of an array.
Even I have tried public oodleListingsUser[] user But it gives error as
No parameterless constructor defined for type of 'oodleListingsUser[]'
for the value which returns only one user !
Now what should i do to solve this issue ?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Try:
public oodleListings[] listings = new oodleListings[0];
Or make it a List<oodleListings> perhaps.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0