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!
Non riesci a trovare un film o una serie Tv? Accedi per crearlo.
Vuoi valutare o aggiungere quest'elemento a una lista?
Non sei un membro?
Risposta da Travis Bell
il 3 novembre, 2013 alle 9:30PM
No, nothing changed.
Apiary aside, what's that error actually mean? Does it reference an invalid object or key?
Risposta da Mark Terborg
il 4 novembre, 2013 alle 9:37AM
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!
Risposta da Travis Bell
il 4 novembre, 2013 alle 9:50AM
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.Risposta da Mark Terborg
il 4 novembre, 2013 alle 10:01AM
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!
Risposta da Travis Bell
il 4 novembre, 2013 alle 10:15AM
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.
Risposta da Mark Terborg
il 4 novembre, 2013 alle 10:35AM
Sorry. That was a typo. Ok. I'll do some more messing around to see if I can figure it out. Thanks.
Risposta da Mark Terborg
il 4 novembre, 2013 alle 11:19AM
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!
Risposta da Travis Bell
il 4 novembre, 2013 alle 11:41AM
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.
Risposta da Mark Terborg
il 4 novembre, 2013 alle 11:48AM
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!
Risposta da Travis Bell
il 4 novembre, 2013 alle 5:34PM
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.