Reputation: 57
I have to parse the following web service:
http://api.mytracemobile.com/mobile.svc/getHotelApp?data={"AvailabilitySearch": {"Authority": { "Currency": "USD" },"Cityname": "Jaipur, India", "CheckInDate": "2017-11-18","CheckOutDate": "2017-11-19", "Searchid": "111111", "Room": [{"Guests": {"Adult": [{ "Title": "Mr" },{ "Title": "Mr" }]}},{"Guests": {"Adult": { "Title": "Mr" }}}],"Nationality": "IN"}}
How can I create a RequestBody for it so ?data= also includes in that request body. Please let me know how this will be implemented Thanks in Advance
Upvotes: 0
Views: 141
Reputation: 103
Read about GSON and Retrofit, there are sufficient articles on both.
Instead of above data sample, Check the dummy sample and Model class to understand the process
Sample: A:{B:"",C:"",D:[{D1:""},{D1:""}]}
Models:
Class1 {@SerializedName("A") private Class2 a; }
Class2 { @SerializedName("B") private String b;
@SerializedName("C") private String c;
@SerializedName("D") private Arraylist<Class3> d; }
Class3 { @SerializedName("D1") private String D1; }
Note: Add Getter setter or constructor in Models to access the values.
After this, You can decrypt the JSON response just by passing reference of Class1.
Read about GSON(for @SerializedName) and then about Retrofit to fetch JSON Response also check this StackOverflow post.
Upvotes: 1