2016-07-22 66 views
1

有这个JSON数据我如何解析JSON阵列到网页视图的Android

"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)); 

网页视图。在我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; 

时能够通过与显示titlecontent,使用下面的代码然而,当我尝试entity它显示null中的WebView

我要去哪里错了

回答

0

尝试:

entity = args.getString("custom_fields.entity"); 

希望它有帮助!

+0

这没有帮助的ith元素或者,还是显示为空 –

0

你的问题是不明确的,按照我的理解,你需要Refugee元素

JSON你已经张贴无效。

为每entity我的理解元素也是JSONObject,所以解析器应该是这样的

.optJSONArray("entity").getJSONObject(i); // i is poistion 

这会给你实体array