2016-11-21 82 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