Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
      [  {
            "question_id": 13,
            "creation_date": 10,
            "name": " certain degrees",
            "tags": [
                "android",
                "sensor"
            ],
.....
...}

]

Here is the api I want to get the tags array ,the tag array contains only index and value,i want to get the array using array object and finally store in array list, i have tried but fail to get the datas..could anybody help me to solve this problem.

    tagarray = jsontagobj.getJSONArray("tags");
                for(int j=0;j<tagarray.length();j++){
                    tagobject = tagarray.getJSONObject(j);
                    if(tagobject!=null){
                    ...// what to add to get the index with value////
                                     tagname.add(.....);
                    }   


}
share|improve this question
    
can you past youy error log –  MuraliGanesan Feb 20 '13 at 7:59
    
@Muraliganesan its not error exactly not getting the data.. –  Sangita Feb 20 '13 at 8:00
    
tagobject = tagarray.getJSONObject(j).toString(); and then add tagobject in your array list tagname.add(tagobject); is it not working for you –  MuraliGanesan Feb 20 '13 at 8:05
    
NO it will not work..as because tagname is string array list and its cant take the object –  Sangita Feb 20 '13 at 8:16
1  
@Sangita : can u plz share all json or json link? –  ρяσѕρєя K Feb 20 '13 at 10:26

2 Answers 2

up vote 1 down vote accepted

because current "tags" array not content any JSONObject it contain only String values . get values as :

// Create Hashmap before starting parsing

HashMap<String,ArrayList<String>> mapQusttags=
                            new HashMap<String,ArrayList<String>>();

//your code here ......

tagarray = jsontagobj.getJSONArray("tags");
// Create ArrayList
ArrayList<String> tagsList = new ArrayList<String>();
 for(int j=0;j<tagarray.length();j++){
     tagsList.add(tagarray.getString(j)); 
  } 

// Store ArrayList inside HashMap with question id

String str_qstid=jsontagobj.getString("question_id");

mapQusttags.put(str_qstid,tagsList);
share|improve this answer
    
THanks for your answer!!! –  Sangita Feb 20 '13 at 8:22
    
@Sangita : see my edit answer –  ρяσѕρєя K Feb 20 '13 at 10:38
    
k..let me check.. –  Sangita Feb 20 '13 at 10:50
    
here based on question id the tag will allocate right.. –  Sangita Feb 20 '13 at 10:53
    
@Sangita : after parsing when u need tags of any question just use ArrayList<String> arrtags=mapQusttags.get(<pass question id here>); then u will get all tags inside arrtags ArrayList –  ρяσѕρєя K Feb 20 '13 at 10:55

You're making it complex, there is no need to get the JSONObject.

ArrayList<String> tagsList = new ArrayList<String>();
tagarray = jsontagobj.getJSONArray("tags");
for(int j=0;j<tagarray.length();j++){
   tagsList.add(tagarray.getString(j)); 
} 
share|improve this answer
    
thanks for your answer its ,,right.. –  Sangita Feb 20 '13 at 8:20
    
i have got your answer but still i have some issues regarding this..can you help –  Sangita Feb 20 '13 at 9:28
    
yes, I can try, what issues are you facing? –  ThePCWizard Feb 20 '13 at 9:52
    
the main thing is when we assign the taglist it came the entire list of the tag minimum 50..i –  Sangita Feb 20 '13 at 10:00
    
I need for each question the allocated tags is min 2 or 3 but it acme entirely.. –  Sangita Feb 20 '13 at 10:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.