0

My jsonobject returns the following string from a php data source:

String[] faili =  new String [] {object.getString("slikaordfail")};
-->
["San Diego_3.jpg","San Diego_2.jpg","San Diego_1.jpg"]

How can I get an array in java from this string?

Tried something like

 List<String> stringList = new ArrayList<String>(Arrays.asList(faili));

but with the same result. It seems that the brackets from the php array are the problem. I don't like do delete them with string operations. There must be a more elegant way.

Debugger shows only one record:

0=  "["San Diego_3.jpg","San Diego_2.jpg","San Diego_1.jpg"]"

Any help will be highly appreciated.

1
  • do not put your object.getstring inside the String Array initialization. the getstring call gives you a one long string, not multiple strings. Commented Apr 8, 2017 at 17:40

1 Answer 1

1

Use Gson library. Create custom class like this Details.

@SerializedName("slikaordfail")
private ArrayList<Details> eventDetailses;

public ArrayList<Details> getEventDetailses() {
    return eventDetailses;
}

public void setEventDetailses(ArrayList<Details> rentDetailses) {
    this.eventDetailses = rentDetailses;
}

 @SerializedName("event_pic")
private String eventPicture;

public String getEventPicture() {
    return eventPicture;
}

public void setEventPicture(String eventPicture) {
    this.eventPicture = eventPicture;
}

And in your Activity call.

Details details = gson.fromJson(result, Details.class);//result is your json data
ArrayList<Details> detailses = details.getEventDetailses();//getImages using detailses arrayList 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for this, but I don't have gson installed. Will try, when I have time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.