0

使用 json jason 解析器,但我没有将多个标记值添加到数组列表中,我想将带有 Actor 的 $t 标记解析到数组列表中。例如

{
"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 标签中获取多个项目到数组列表中。我的代码是:

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 - 这是数组列表。maprole-这是哈希图。任何帮助表示赞赏。

4

2 回答 2

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());
    }
于 2012-12-27T07:14:06.337 回答
0

您的 JSON 无效。当我向下滚动您的 JSON 列表时,您已经定义了同名的数组。这就是为什么它采用多个关键“角色”值。

于 2012-12-27T06:52:32.970 回答