2016-11-21 81 views
-1

我需要帮助来解决问题。我使用Wordpress APIRest从我的页面获取JSON。服务REST格式JSON Wordpress

@Override 
public void onFeed(JSONArray array) { 

    posts=new ArrayList<>(); 

    int length=array.length(); 
    for(int i=0; i<length;i++){ 
     JSONObject object= array.optJSONObject(i); 
     Spanned desc= Html.fromHtml(object.optString("excerpt")); 
     //Spanned tit=Html.fromHtml(object.optString("title")); 
     Post post=new Post(object.optString("title"), desc.toString(),object.optString("featured_image")); 
     posts.add(post); 
    } 

    postAdapter.addAll(posts); 
    postAdapter.notifyDataSetChanged(); 
} 

这个功能给我用JSON格式:

"title": 
    { 
     "rendered": "TITLE POST" 
    }, 

的问题是,我只是想拿到冠军,但JSON让我“变得”太标签。当我将它打印在我的文本框上时,它显示为:TITLE POST

任何帮助?由于

回答

0

获得 “冠军” 的方法如下,

String title = object.getJSONObject("title").getString("rendered"); 
+1

它工作的感谢。 – Francisco