![](/img/trans.png)
[英]Error while using body.json() for parsing response from http.get()
[英]Parsing JSON response to get body from HTML
我收到以下json響應。 我如何從中獲取主體內容,以便可以檢查以下類似json的情況:
{
"googleplus": {
"error_message": "User did not grant permission + access_denied",
"error_code": 2020
}
}
我嘗試了以下語句來獲取html的正文,但似乎與if語句中的條件不匹配
mWebView.loadUrl("javascript:window.HTMLOUT.showHTML(document.getElementsByTagName('body')[0].innerHTML);");
class MyJavaScriptInterface
{
@JavascriptInterface
public void showHTML(String html)
{
if(html.contains(some string from body of html))
{
//do something
}
}
}
我想要的是if條件應使用的正文中的什么字符串,以便它成為真
因為你的json是給定的
{
"googleplus": {
"error_message": "User did not grant permission + access_denied",
"error_code": 2020
}
}
解析json數據如下
JSONObject primaryObject=new JSONObject(//pass yours json string here);
JSONObject googleplus=primaryObject.getJSONObject("googleplus");
String error_message=googleplus.getString("error_message");//use it if you need
String error_code=googleplus.getString("error_code");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.