gpt4 book ai didi

json - 从黑莓中的 Json 获取数据

转载 作者:行者123 更新时间:2023-12-04 05:00:28 24 4
gpt4 key购买 nike

我正在尝试从该 Json 中获取内容:

{
"status":"ok",
"page":
{
"id":2,
"type":"page",
"slug":"about-us",
"url":"http:\/\/ugo.offroadstudios.com\/about-us\/",
"status":"publish",
"title":"About Us",
"title_plain":"About Us",
"content":"<p><strong>Lorem Ipsum<\/strong>\u00a0is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry&#8217;s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.<\/p>\n",
"excerpt":"Lorem Ipsum\u00a0is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry&#8217;s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic [...]",
"date":"2012-07-03 09:03:01",
"modified":"2013-02-15 18:20:04",
"categories":[],
"tags":[],
"author":{"id":1,"slug":"sociannel-app","name":"sociannel-app","first_name":"sociannel-app","last_name":"","nickname":"sociannel-app","url":"","description":"not filled yet"},
"comments":[],
"attachments":[],
"comment_count":0,
"comment_status":"closed"
}
}

这是我用来从 json 获取内容的代码:

String strURL = "http://ugo.offroadstudios.com/api/get_page/?id=2;deviceside=true"; 
webConnection wb = new webConnection();
String res = wb.getJson(strURL);

try {
JSONObject object = new JSONObject(res);
if(object.getString("status") == "error")
{
Dialog.alert("Invalid "+object.getString("status"));

}
else
{
String content = object.getString("page.content");
Dialog.alert(content);
RichTextField aboutus = new RichTextField("");
this.setTitle(content);
add(aboutus);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
System.out.println("EX is "+e);
e.printStackTrace();
}

它给了我一个错误“找不到页面内容”。

最佳答案

而不是使用 object.getString("page.content") ,试试这个:

    JSONObject page = object.getJSONObject("page");
String content = page.getString("content");
Dialog.alert(content);

您只需将该过程分为两步,首先获得 page对象,然后检索 content从那。

关于json - 从黑莓中的 Json 获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16196270/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com