All of a sudden I'm having customers complaining about an error every time they try to search for a movie using my program. I haven't changed any code on my end in quite some time. The error when parsing the JSON is "Input string was not in a correct format." When I run a test on apiary the following is shown in red:
"1": The ‘production_countries,1’ property is required. | The production_countries,1 property must be an object (current value is undefined). { "iso_3166_1": "US" The ‘production_countries,1,iso_3166_1’ property is required. "name": "United States of America" The ‘production_countries,1,name’ property is required.
Did something change in the API to cause this? If so, do you have any idea how I can easily fix this? I've created a custom .net dll based off TMDbLib using Newtonsoft.Json instead.
Thanks!
Can't find a movie or TV show? Login to create it.
Want to rate or add this item to a list?
Not a member?
Reply by Travis Bell
on November 3, 2013 at 9:30 PM
No, nothing changed.
Apiary aside, what's that error actually mean? Does it reference an invalid object or key?
Reply by Mark Terborg
on November 4, 2013 at 9:37 AM
Thank you for the response. I basically learn this stuff as I go, so if I seem like a newbie, sorry. Here is what I've got, hopefully you can help!
It is throwing the error here: Movie resp = JsonConvert.DeserializeObject(response, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
Here is my Movie class:
I am not sure which one is actually throwing the error. I only brought up production_countries because that is what was in red on apiary. Do you see anything? Like I said, it was working fine for months for everybody using my program, but all of a sudden it isn't working for any search.
If you need any more info, I'd be happy to get it for you. Thanks!
Reply by Travis Bell
on November 4, 2013 at 9:50 AM
Hi Mark,
Do you have an example search that is throwing the error?
I am wondering if it's the combination
poster_path
andbackdrop_path
definitions you have there being set to strings. If no image exists the result is null, not an empty string. I have absolutely zero knowledge about C# but if things are strongly typed like that, the JSON parser could be throwing an error when null comes in expecting to be a string.Reply by Mark Terborg
on November 4, 2013 at 10:01 AM
Example that is throwing the error:
The NullValueHandling = NullValueHandling.Ignore in the JsonSerializerSettings should ignore the nulls so they don't throw an error.
Thanks!
Reply by Travis Bell
on November 4, 2013 at 10:15 AM
Is that
releasese
the actual response you're trying to append? That looks like a typo but I'm not clear if it was something that got mucked around pasting it in here or if that's what your code actually says.I don't see anything else that sticks out though.
Reply by Mark Terborg
on November 4, 2013 at 10:35 AM
Sorry. That was a typo. Ok. I'll do some more messing around to see if I can figure it out. Thanks.
Reply by Mark Terborg
on November 4, 2013 at 11:19 AM
FYI: I figured it out. It looks like the height and width for each of the appended images were no longer integers. For example: the response text shows: "height":1080.0 So it was flipping out when it saw the decimal point. I switched them to parse as a double instead of an integer and it now parses them correctly. Thanks!
Reply by Travis Bell
on November 4, 2013 at 11:41 AM
Interesting!
I should probably coerce them back to integers, but as long as the change you just made will just with that we're good.
I'll get this fixed up later this afternoon.
Reply by Mark Terborg
on November 4, 2013 at 11:48 AM
Great! Yeah, it would be better on my end if you switch them back to integers so I don't have to send out an update... but like you said, either way will work. Thanks!
Reply by Travis Bell
on November 4, 2013 at 5:34 PM
Fix for this was pushed about 10 minutes ago but we'll have to wait for all of the already cached items to expire from the cache. Should be fixed for all newly cached items from here on in.