问题
I'm using GSON for parsing response from a Volley request and got stuck in creating a GSON format when the response has a property that can either be a string or an object or an array perhaps... e.g content
{
"data": {
"date_updated": "2016-12-21T03:55:29.955Z",
"date_created": "2016-12-21T03:55:29.955Z",
"content": "String here",
"content": {
"longitude": "",
"latitude": ""
},
"status": "PROC",
"_id": "5859fd31a93c7235575d62db"
}
}
My current process in creating a GSON model is:
- Create a java class
- Right click and select Generate > GSONFormat
- Paste the object I'm trying to convert then use it in Volley. I tried the above object but it doesn't proceed. I think it's because of same property name.
Thanks for your advice.
回答1:
You can use GsonFormat, you can look this: https://github.com/zzz40500/GsonFormat
来源:https://stackoverflow.com/questions/41255196/how-to-generate-gsonformat-for-a-property-that-can-either-be-an-object-or-string