-5

I am developing an app using json api and want to implement following format api into my app. How do i implement this in my project using android studio 2.3?

{
    "getdetailsasanas": [
        {
            "asanaid": 1,
            "asananame": "Half easy gas release pose",
            "duration": 1,
            "imageurl": "http://www.yogapoint.com/iOS/images/half-easy-gas-release-pose.jpg",
            "imageversion": 2,
            "audiourl": "http://www.yogapoint.com/iOS/audio/half-easy-gas-release-pose.mp3",
            "audioversion": 1,
            "videourl": "NULL",
            "videoversion": 0,
            "StepsForAsana": [
                {
                    "stepnumber": 1,
                    "stepdesc": "Step 1",
                    "stepimg": "http://www.yogapoint.com/iOS/images/asana-step/half-easy-gas-release-pose-step1.jpg",
                    "stepimgeversion": 0,
                    "imgethumbversion": 1,
                    "imgethumburl": "http://www.yogapoint.com/iOS/images/asana-step/half-easy-gas-release-pose-step1-tb.jpg"
                },
                {
                    "stepnumber": 2,
                    "stepdesc": "Step 2",
                    "stepimg": "http://www.yogapoint.com/iOS/images/asana-step/half-easy-gas-release-pose-step2.jpg",
                    "stepimgeversion": 0,
                    "imgethumbversion": 1,
                    "imgethumburl": "http://www.yogapoint.com/iOS/images/asana-step/half-easy-gas-release-pose-step2-tb.jpg"
                }
            ]
        }
    ]
}
5
  • Show your work . Commented Jul 19, 2017 at 5:59
  • Did you try googling it? It would surprise me if you would be the first person in the world that is going to parse JSON on an Android platform Commented Jul 19, 2017 at 6:03
  • See this stackoverflow.com/questions/9605913/… Commented Jul 19, 2017 at 6:03
  • And see this same as your response structure link Commented Jul 19, 2017 at 6:06
  • plz suggest me how do i implement this ? Commented Jul 19, 2017 at 6:06

5 Answers 5

0

You can use JSONObject its default supplied with android SDK:

String json = "some JSON";
JSONObject jsonObject = new JSONObject(json);

Than you can use methods like

getBoolean(String key)
getDouble(String key)

etc

Or you can use google gson library which is in my opinion better, but you will need to include it as dependency in gradle.

There is github for the Gson.

There is Gson API

Sign up to request clarification or add additional context in comments.

Comments

0

Use Gson library . Best way to parse the responses.Your can user GsonFormat plugin to generate the model for response.

Comments

0

Have a look on gson. It's a easy serializer for json.

Comments

0

It's my pleasure to answer your question. You can do like this.

try {
        JSONObject jsonObject = new JSONObject(result);
        JSONArray jsonArray = jsonObject.getJSONArray("getdetailsasanas");
        for (int i = 0; i < jsonArray.length(); i++) {
            String asanaid = jsonArray.getJSONObject(i).getString("asanaid");
            String asananame = jsonArray.getJSONObject(i).getString("asananame");
            String duration = jsonArray.getJSONObject(i).getString("duration");
            String imageurl = jsonArray.getJSONObject(i).getString("imageurl");
            String imageversion = jsonArray.getJSONObject(i).getString("imageversion");
            String videourl = jsonArray.getJSONObject(i).getString("videourl");
            String videoversion = jsonArray.getJSONObject(i).getString("videoversion");
            JSONArray StepsForAsanaArray = jsonArray.getJSONObject(i).getJSONArray("StepsForAsana");
            for (int j = 0; j < StepsForAsanaArray.length(); j++) {
                String stepnumber = jsonArray.getJSONObject(j).getString("stepnumber");
                String stepdesc = jsonArray.getJSONObject(j).getString("stepdesc");
                String stepimg = jsonArray.getJSONObject(j).getString("stepimg");
                String stepimgeversion = jsonArray.getJSONObject(j).getString("stepimgeversion");
                String imgethumbversion = jsonArray.getJSONObject(j).getString("imgethumbversion");
                String imgethumburl = jsonArray.getJSONObject(j).getString("imgethumburl");
            }
        }

    } catch (JSONException e) {
        e.printStackTrace();
    }

8 Comments

you must decrease your implementation
sure.I got it.But I don't know what he needs.
But I think that Gson or Fastjson will be better
how do i show result of above string to text
@KeLiuyue is for newbie programers
|
0

Use like with this code:

JSONArray getdetailsasanas = new JSONArray(stringData);
for (int p = 0; p < getdetailsasanas.length(); p++) {
    try {
        JSONObject data = getdetailsasanas.getJSONObject(p);
        JSONObject asanaid    = data.getJSONObject("asanaid");
        JSONObject stepnumber = data.getJSONObject("stepnumber");
        JSONObject stepnumber = data.getJSONObject("stepnumber");


        //get data from objetcs
        String asananame = asanaid.getString("asananame");
        int duration = asanaid.getInt("duration");
        String imageurl = asanaid.getString("imageurl");


    } catch (JSONException e) {
        e.printStackTrace();
    }
}

1 Comment

@Rohi my post updated

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.