[英]Trying to extract data from JSON or JSONP using WOT api
I was using WOT(web of trust) api.In this, i am getting response in this format, 我使用的是WOT(信任网络)API。在这种情况下,我收到的响应格式如下:
process( {
"www.google.com": {
"target": "google.com",
"0": [ 95, 84 ],
"1": [ 95, 84 ],
"2": [ 95, 84 ],
"4": [ 93, 78 ],
"categories": {
"501": 92
}
}
} )
I am very confused to extract the data string from this format of JSON. 我很困惑要从这种JSON格式提取数据字符串。 I searched a lot but could not find any way. 我搜索了很多,但找不到任何方法。
I want to extract from categories... means I want to save '502' value. 我想从类别中提取...意味着我想保存“ 502”值。
Problem : JSON Objects starts with "{" and ends with "}", the response you're getting is not a correct JSON Format. 问题: JSON对象以“ {”开头,以“}”结尾,您得到的响应不是正确的JSON格式。
Analysis : Why? 分析:为什么? you might ask, the response started with p
char from process
, and ends with )
char, instead of "}". 您可能会问,响应以process
p
char开头,以)
char结尾,而不是“}”。
Solution : To fix the json, we will need to remove the process (
and )
string, so that the response can be parsed as JSON. 解决方案:要修复json,我们将需要删除process (
和)
字符串,以便将响应解析为JSON。
Hint : Use String.replace()
method to replace the unwanted string with empty string ""
, more information here and here 提示:使用String.replace()
方法将不需要的字符串替换为空字符串""
, 此处和此处的更多信息
Hope this helps, and Good Luck! 希望这会有所帮助,祝你好运! ^^ ^^
Reid 里德
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.