TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
John Riker
NA
85
15.8k
Changing JSON from Source
Dec 10 2020 10:40 AM
I have a program running that's been flawless up until now. I pull several data feeds from the same vendor and they were all the same. Now it seems for some reason there is one field that was a JSON array and now isn't for one of the feeds but hte rest are still the same. And on top of it, that feed changes from pull to pull. No idea why.
Anywho, is there a way to deal with this without creating a whole separate set of classes to deal with this and doubling my processing to use one group or another?
So essentially I took the JSON and pated as JSON into my program. The part that's an issue is:
public
class
Regionalratings
{
public
string region { get; set; }
public
string rating { get; set; }
public
object disclaimer { get; set; }
public
Subrating[] subratings { get; set; }
public
object consumerAdvice { get; set; }
public
object ratingIcon { get; set; }
}
it's the Subrating[]. Sometimes it needs to be Subrating1[] and sometimes Subrating1
The error I get is:
Unhandled Exception: Newtonsoft.Json.JsonSerializationException: Cannot deserialize the current JSON array (e.g. [1,2,3]) into type
'ShowWebsiteDownloader.Regionalratings'
because the type requires a JSON object (e.g. {
"name"
:
"value"
}) to deserialize correctly.
To fix
this
error either change the JSON to a JSON object (e.g. {
"name"
:
"value"
}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List
that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.
Path
'result.data[1].regionalRatings'
, line 1, position 4570.
Funny part is I have no need for that field physically and it's usually empty. Not sure if there even though would be dangerous, a way to fill the data as it can and skip what it can't.
Call it's failing on is:
ShowWebsiteDownloader.Rootobject rootObject = JsonConvert.DeserializeObject
(rawJSON);
Reply
Answers (
1
)
Slick slider with video carousel
MVC Login Apply to WinForms