-4

MY JSON looks like this. I just need to set these values in the layout of the fragment. So that the details about this product will be displayed.



{
  "adid": 5,
  "uid": 1130,
  "userName": "Maëly",
  "cid": 5,
  "brand": null,
  "model": null,
  "title": "Nummular dermatitis",
  "description": "Nam sa dea ss "
  "address": "9795 Debra Center",
  "price": 1544,
  "photo1": "../../../img/mobile/oneplus/3t/3t-1.jpg",
  "photo2": null,
  "photo3": null,
  "photo4": null,
  "ip_add": null,
  "created": 1493921700000,
  "expiryDate": null,
  "published": true,
  "sold": null,
  "featured": true,
  "cond": true,
  "price_neg": true,
  "used_for": "8",
  "views": 1575,
  "city": "Kathmandu",
  "landmark": null,
  "quality": null,
  "alert": null,
  "features": [

  ]
}

Xantosh Lamsal
  • 349
  • 5
  • 14

3 Answers3

1

Ever had a glance at the Retrofit documentation? http://square.github.io/retrofit/?

You can make synchronous, or asynchonous calls to the service, you create for your interface and do with the result as you please. If you want the data shown in a fragment, you'll probably do an asynchonous call and when you get back the data (which via the Gson converter should automatically be converted from JSON to your data model classes) you can e.g. show the list of data objects in a ListView or whatever.

Ridcully
  • 23,362
  • 7
  • 71
  • 86
1

do step that SpaceBison Suggest Then do this, if for e.g. JSONSCHEMATOPOJO create class POJO for you then do this.

try{
JSONObject object = new JSONObject(string);
Gson gson= new Gson();
POJO p = gson.fromJson(object,POJO.class)'
}catch(JSONException){
e.printStackStra();
}
Himeshgiri gosvami
  • 2,559
  • 4
  • 16
  • 28
0

I'd suggest using a Gson converter. You can generate Gson POJO definitions with jsonschema2pojo - despite the name it also can use an example JSON.

SpaceBison
  • 2,525
  • 1
  • 21
  • 38