I need to parse a JSON item which could be defined as follows:
{
...
"itemName": ""
...
}
or
{
...
"itemName": {
}
...
}
Basically, the feed i am reading from defines itemName as an empty string if there is no value, otherwise it is a regular JSON object which i can parse fine.
I believe this is what is causing the GSON error i am experiencing, although i may be wrong.
How can I parse such a JSON feed including fields defined like i have shown above, without causing a GSON error? Or how can i suppress this error and move on parsing?
here is the logcat:
ERROR/AndroidRuntime(32720): Caused by: com.google.gson.JsonParseException: Expecting object found: ""
I am using the GSON included in the AdMob 4.0.4 jar
You’d need to implement a custom deserializer for this. Following is one example.
This could easily be changed to return an empty
Innerinstance instead ofnull, depending on what’s desired, of course.