Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get json which has multiple values in a string in android

I have a json which has multiple values separated by commas which is in the form of array.I want to get skills and platforms string separately.Can you please help me?

I want to show skills string and platforms string in text.

Please help me.

The format is:

{
    "data": [
        {
            "skills": "ANDROID SDK, ANIMATION, ANGULARJS,",
            "platforms": "IOS Application, Social Networking, Online shopping Sites, Web Application"
        }
    ],
    "status": 100
}
like image 547
binila Avatar asked Jan 31 '26 04:01

binila


2 Answers

Try this one

                       try {
                            JSONObject ob = new JSONObject(response);

                            int status = ob.getInt("status");

                            if (status == 100) {

                            JSONArray ja = ob.getJSONArray("data");

                            for (int i = 0; i < ja.length(); i++) {

                                values = new HashMap<>();

                                JSONObject vj = ja.getJSONObject(i);

                                String skills = vj.getString("skills "));

                                String platforms=vj.getString("platforms"));

                                data.add(values);
                            }

split these 2 strings using 'split()'

                  List<String> skillsArray = Arrays.asList(skills.split(","));
                  List<String> platformsArray= Arrays.asList(platforms.split(","));
like image 155
akash bs Avatar answered Feb 02 '26 22:02

akash bs


String in = "your json";
JSONObject jsonObj = new JSONObject(in);

// Getting JSON Array node
JSONArray jsonarray = jsonObj.getJSONArray("data");

for (int i = 0; i < jsonarray.length(); i++) {
    JSONObject jsonobject = jsonarray.getJSONObject(i);
    String skills = jsonobject.getString("skills");
    String platforms = jsonobject.getString("platforms");
}
like image 39
Abubakker Moallim Avatar answered Feb 02 '26 22:02

Abubakker Moallim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!