Francisco Francisco - 13 days ago 6
reST (reStructuredText) Question

Service REST format JSON Wordpress

I need help to solve a problem. I´m using Wordpress APIRest to get JSON from my page.

@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();
}


This function give me the JSON with this format:

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


The problem is that i only want to get the title but the JSON let me the label "rendered" too. When I print it on my textfield it is: rendered: TITLE POST

Any help? Thanks

Answer

Get the "title" as follows,

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