本文介绍了获得使用ArrayObject的和存储的值在数组列表中的数组索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
[{
question_id:13,
CREATION_DATE:10,
名:一定程度,
标签:
机器人,
传感器
]
.....
...}
]
下面是我想要得到的标签阵列的API,标签阵列只包含指数和价值,我想用数组对象获取数组终于在数组列表保存,我已经尝试,但未能得到DATAS。 .could谁能帮我解决这个问题。
tagarray = jsontagobj.getJSONArray(标记);
对于(INT J = 0; J< tagarray.length(); J ++){
tagobject = tagarray.getJSONObject(J);
如果(tagobject!= NULL){
... //添加什么来获取与价值指数////
tagname.add(.....);
}
}
解决方案
由于当前的标签阵列没有任何内容的JSONObject它仅包含字符串值。得到值:
开始分析之前//创建哈希映射
HashMap的<字符串,ArrayList的<字符串>> mapQusttags =
新的HashMap<字符串,ArrayList的<字符串>>();
//你的code在这里......
tagarray = jsontagobj.getJSONArray(标记);
//创建的ArrayList
ArrayList的<字符串> tagsList =新的ArrayList<字符串>();
对于(INT J = 0; J< tagarray.length(); J ++){
tagsList.add(tagarray.getString(J));
}
里面的HashMap //商店的ArrayList有问题ID
串str_qstid = jsontagobj.getString(question_id);
mapQusttags.put(str_qstid,tagsList);
[ {
"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(.....);
}
}
解决方案
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);
这篇关于获得使用ArrayObject的和存储的值在数组列表中的数组索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!