使用json jason解析器,但我没有在arraylist中添加多个标记值,我想将带有Actor的$ t标记解析为arraylist.such
{
"media$group":{
"media$credit":[
{
"$t":"Murison Dunn",
"role":"Writer",
"scheme":"urn:ebu"
},
{
"$t":"Randolph Scott",
"role":"Actor",
"scheme":"urn:ebu"
},
{
"$t":"Forrest Tucker",
"role":"Actor",
"scheme":"urn:ebu"
},
{
"name":"Mala Powers",
"role":"Actor",
"scheme":"urn:ebu"
},
{
"$t":"J. Carrol Naish",
"role":"Actor",
"scheme":"urn:ebu"
},
{
"$t":"Edgar Buchanan",
"role":"Actor",
"scheme":"urn:ebu"
},
{
"name":"Myron Healey",
"role":"Actor",
"scheme":"urn:ebu"
},
{
"$t":"Howard Petrie",
"role":"Actor",
"scheme":"urn:ebu"
},
{
"name":"Ray Teal",
"role":"Actor",
"scheme":"urn:ebu"
},
{
"$t":"William Forrest",
"role":"Actor",
"scheme":"urn:ebu"
},
{
"$t":"Denver Pyle",
"role":"Actor",
"scheme":"urn:ebu"
},
{
"$t":"Trevor Bardette",
"role":"Actor",
"scheme":"urn:ebu"
},
{
"$t":"Kenneth Tobey",
"role":"Actor",
"scheme":"urn:ebu"
}
]
},
{
"media$group":{
"media$credit":[
{
"$t":"Murison",
"role":"Writer",
"scheme":"urn:ebu"
},
{
"$t":"Scott",
"role":"Actor",
"scheme":"urn:ebu"
},
{
"$t":"Tucker",
"role":"Actor",
"scheme":"urn:ebu"
}
{
"name":"Powers",
"role":"Actor",
"scheme":"urn:ebu"
}
]
},
{
"media$group":{
"media$credit":[
{
"$t":"Dunn",
"role":"Writer",
"scheme":"urn:ebu"
},
{
"$t":"J.Naish",
"role":"Actor",
"scheme":"urn:ebu"
},
{
"$t":"Buchanan",
"role":"Actor",
"scheme":"urn:ebu"
},
{
"$t":"Healey",
"role":"Actor",
"scheme":"urn:ebu"
},
{
"$t":"Petrie",
"role":"Actor",
"scheme":"urn:ebu"
}
]
}
}
但是我的主要问题是我需要从$ t标签中获取多个项目到arraylist。我的代码是:
JSONObject jsonmediagrop=videoObject.getJSONObject("media$group");
JSONArray itemsmediarole = jsonmediagrop.getJSONArray("media$credit");
for(int l=0;l<itemsmediarole.length();l++){
JSONObject Objectrole = itemsmediarole.getJSONObject(l);
strrole=Objectrole.getString("Role");
Log.v("Role", strrole);
if(strrole.equals("Actor"))
{
stractor=Objectrole.getString("$t") + "," + stractor;
Log.v("stractor", stractor);
maprole.put("$t", stractor);
myrolelist.add(maprole);
}
}
myrolelist - 这是arraylist。 maprole-这是hashmap。 任何帮助表示赞赏。
答案 0 :(得分:2)
好的,在另一个回答中阅读你的评论后,我决定帮助你
解析我的问题也很多。经过大量的研究
在我的代码中,我试图获得rstp url links
我希望你能看一下并解决你的问题
这是我的工作代码
try {
JSONObject obj = new JSONObject(json);
String entry = obj.getString("entry");
JSONObject enObj = new JSONObject(entry);
String group = enObj.getString("media$group");
JSONObject grObj = new JSONObject(group);
String content = grObj.getString("media$content");
JSONArray array = grObj.getJSONArray("media$content");
for(int j=0; j<array.length(); j++){
JSONObject thumbs = array.getJSONObject(j);
String url = thumbs.getString("url");
urls[j] = url;
Log.d(TAG, url);
//data.setThumbUrl(thumbUrl);
}
Log.v(TAG, content);
} catch (Exception e) {
Log.e(TAG, e.toString());
}
对你来说,这可能就是诀窍:
try {
JSONObject obj = new JSONObject(json);
String entry = obj.getString("entry");
JSONObject enObj = new JSONObject(entry);
String group = enObj.getString("media$group");
JSONObject grObj = new JSONObject(group);
JSONArray array = grObj.getJSONArray("media$credit");
for(int j=0; j<array.length(); j++){
JSONObject credits = array.getJSONObject(j);
String role = credits.getString("role");
Log.d(TAG, role);
}
} catch (Exception e) {
Log.e(TAG, e.toString());
}
答案 1 :(得分:0)
您的JSON无效。当我向下滚动您的JSON列表时,您已经定义了相同名称的数组。这就是它采用关键“角色”的多个价值的原因。