我有这个JSON数据
"posts":[{
"date":"2016-02-10 10:28:42",
"categories":[{}],
"tags":[],
"author":{"name":"admin"},
"custom_fields":{
"ref_number":["ITB NUMBER: ITB\/002\/2016"],
"deadline":["26 February, 2016"],
"entity":["Refugees (xxx)"]
}
我想在我的entity
JSONParser.java
Post post = new Post();
// Configure the Post object
post.setTitle(postObject.optString("title"));
post.setDate(postObject.optString("date", "N/A"));
post.setContent(postObject.optString("content", "N/A"));
post.setCfs(postObject.getJSONObject("custom_fields").optJSONArray("entity").getString(0));
到我的 Webview 。在我的PostFragment.java
id = args.getInt("id");
//Title and date pass successfully
title = args.getString("title");
String date = args.getString("date");
//but the entity displays null
entity = args.getString("entity");
//author is passed and it displays well/successfully
String author = args.getString("author");
// Construct HTML content
// html for entity to webview
html += "<h2>" + entity + "</h2>";
html += "<h3>" + title + "</h3>";
// The actual content
html += content;
能够传递并显示title
和content
,但是当我尝试entity
时,它会在网页浏览中显示null
我哪里出错
答案 0 :(得分:0)
尝试:
entity = args.getString("custom_fields.entity");
希望它有所帮助!
答案 1 :(得分:0)
您的问题不明确,根据我的理解,您需要Refugee
元素
您发布的JSON
无效。
根据我的理解,entity
的元素也是JSONObject
,因此解析器应该是这样的
.optJSONArray("entity").getJSONObject(i); // i is poistion
这将为您提供实体的ith
元素 array