1

I am getting json response in array form like this

 ["Monday","Wednesday","Friday"]

, but it is not saving as a array in android, I am storing that in a string like this

 String daysOfInterest = map.get("daysOfinterest");

 [{"careTypeId":"10","careTypeName":"Vacation Care","daysOfinterest":["Tuesday","Thursday","Saturday"],"childDaysOfInterestId"‌​:"424"},
  {"careTypeId":"10","careTypeName":"Vacation Care","daysOfinterest":["Monday","Wednesday","Friday"],"childDaysOfInterestId":"‌​425"}] 

this is my response and I am storing that daysofInterest in hashmap...and getting using hashmap

But I want to get that in a array form

2
  • What is the exact response and how are you trying to store it in an array? Post the code that you tried. Commented Aug 3, 2016 at 10:19
  • [{"careTypeId":"10","careTypeName":"Vacation Care","daysOfinterest":["Tuesday","Thursday","Saturday"],"childDaysOfInterestId":"424"},{"careTypeId":"10","careTypeName":"Vacation Care","daysOfinterest":["Monday","Wednesday","Friday"],"childDaysOfInterestId":"425"}] this is my response and I am storing that daysofInterest in hashmap...and getting using hashmap Commented Aug 3, 2016 at 10:21

3 Answers 3

1

you can convert the json array into a java array with this

ArrayList<String> list = new ArrayList<String>();     
JSONArray jsonArray = (JSONArray)jsonObject; 
if (jsonArray != null) { 
   int len = jsonArray.length();
   for (int i=0;i<len;i++){ 
    list.add(jsonArray.get(i).toString());
   } 
} 
String[] myArray = list.toArray(new String[list.size()]);

then you can pass the array elements to your map. more info here Convert Json Array to normal Java Array

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

Comments

0
GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson = gsonBuilder.create();
Days[] daysArray = gson.fromJson(jsonString, Days[].class);

Here is Gson library and here is example.

Comments

0

Hope this is useful.

yourstring is ["AA", "BB", "CC"]

if (!yourstring.equals("")) {
    String[] type = yourstring
    .replace("[", "")
    .replace("]", "")
    .replace("\"", "")
    .split(",");
}

Comments

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.