gson

Gson: How do I parse polymorphic values that can be either lists or strings?

南楼画角 提交于 2019-12-13 08:28:20
问题 I need to parse a JSON file that contains long list of customers. In the JSON file each customer may have one id as a string: { "cust_id": "87655", ... }, or a few ids as an array: { "cust_id": [ "12345", "45678" ], ... }, The Customer class is as below: public class Customer { @SerializedName("cust_id") @Expose private String custId; public String getCustId() { return custId; } public void setCustId(String custId) { this.custId = custId; } } I parse the JSON using Gson: Gson gson = new Gson(

Parsing nested Json Objects with Gson

瘦欲@ 提交于 2019-12-13 08:24:29
问题 I am new to Gson parsing ,did some examples , but this time my json is much complex it looks like this { "message": "Ok", "code": 200, "data": { "storage": { "39": { "weight": 22000, "verificationPackageRequested": null, "id": 39, "countryCode": "US", "photosPackageRequested": null, "created": "2014-12-30 11:27:57", "ItemPrice": 224.99, "ItemTitle": "Apple iPad Mini MF432LL/A (16GB, Wi-Fi, Space Gray )", "PhotoThumbnail": "/upload/storage-products/b8c2839010a8c5aae21df3b9e57125d0

Does retrofit interfaces support templated callbacks

核能气质少年 提交于 2019-12-13 08:01:31
问题 I have an API the returns a standard reply for all requests that gets parsed by gson/retrofit. public class ServerReply<T> { @Expose private String status; @Expose private T data; @Expose private String message; } I have an interface for Retrofit that will return a list of users inside of serverReply. public interface Test { @POST("/Test") void runTest(@Body Body body, Callback<ServerReply<List<User>>> response); } I would like to get a different list of objects depending on the content of

Parsing JSON String as simple as possible with GSON

∥☆過路亽.° 提交于 2019-12-13 07:48:00
问题 Using GSON, how can i return a single key from a Multidimensional Json String? Here is the Multidimensional Json String: {"statusCode":0,"statusDescription":"OK","data":{"user":{"id":xxx,"company_id":xxx,"account_type":"5","enable_locations":true,"intuit_user_id":null,"nick_name":"xxx","is_owner":"1","enabled":"1"},"session_token":"xxx"}} I want to return the "session_token" key value. I'm trying this: class app { static class Response { String session_token; } public void getSessionToken() {

Creating lists of dynamic types

梦想的初衷 提交于 2019-12-13 07:45:55
问题 So, I'm working right now on trying to figure out how to parse a large number of different JSON objects without having to hard-code functions to serialize and deserialize each of the objects. I started using Gson, and that has been working pretty well. A problem begins to appear though when I am trying to use a list of objects. I would like to create a function that will work with any of my data model objects that I can pass a JSONArray and the class type that the JSON contains, so that I

Android Json GSon prom

為{幸葍}努か 提交于 2019-12-13 07:31:45
问题 i am trying to GSOn for parsing JSON. Here is my code: public class ProgramList { private List<Program> programs; public List<Program> getPrograms() { return programs; } public void setPrograms(List<Program> programs) { this.programs = programs; } } public class Program { private String id; private String startTime; private String endTime; private String showDate; private String title; private String episodeTitle; private String description; private String duration; private String showLink;

parse json in android [duplicate]

夙愿已清 提交于 2019-12-13 07:20:57
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: JSON Parsing in Android As I find out I need to use Gson class to parse json to Java object in android. It's quite easy to parse simple varables or array, but I don't know how to parse more complex json string, my json look like this: {"selected_id":3, "data":[{"id":"3","score":"1534"},{"id":"1","score":"1234"}]} Can anyone help me how to do this? 回答1: //Model class class Model { private String mId ; private

Gson fromJson to java class structure where property names are not known [duplicate]

会有一股神秘感。 提交于 2019-12-13 07:16:07
问题 This question already has answers here : Correct way for parsing JSON objects containing arrays in Java Servlets (with Gson for example) (3 answers) Closed 4 years ago . I have this json: { "details": { "interest": { "label": "example1", "value": "19,9", "symbol": "%" }, "monthly_invoice": { "label": "example2", "value": "29", "symbol": "eur" }, "start_fee": { "label": "example3", "value": "0", "symbol": "eur" }, "monthly_pay": { "label": "example4", "value": "58", "symbol": "eur" } } } The

How do I send an object with arbitrary types in it to another activity?

你说的曾经没有我的故事 提交于 2019-12-13 06:57:39
问题 I'm pretty new to Android programming and I've ran into this issue. I have an object I am trying to send into a new activity, which is an instance of this class: public final class BusinessEntity extends com.google.api.client.json.GenericJson { /** * The value may be {@code null}. */ @com.google.api.client.util.Key private Contact contact; /** * The value may be {@code null}. */ @com.google.api.client.util.Key @com.google.api.client.json.JsonString private java.lang.Long id; /** * The value

Retrieve data using Gson

只谈情不闲聊 提交于 2019-12-13 06:25:25
问题 I have pasted my code below and would appreciate it if someone would help me work through it. When I run my activity a list should be getting updated inside of my app. I haven't been able to pull in any data though. When I log first I get [] and nothing else. If I check the size it comes back as 0 . *I am expecting to retrieve the id, name, and size and place them in textviews within a listview. When I access my URL string from my browser I get this: { "begin": [ {"id":1,"name":"1","size":2},