当前位置:首页>开发>正文

网页上扒下来的json数据怎么解析 js怎么解码被json的数据

2023-07-02 19:43:46 互联网 未知 开发

 网页上扒下来的json数据怎么解析 js怎么解码被json的数据

网页上扒下来的json数据怎么解析

抓页面的数据我知道你可以试试看这个,请自行改一下网址=="publicStringIP()throwsIOException{StringIP=nullURLurl=newURL("http://iframe.ip138.com/ic.asp")URLConnectionconn=url.openConnection()conn.setRequestProperty("User-Agent","Mozilla/5.0(WindowsUWindowsNT5.1en-USrv:1.9.2.15)Gecko/20110303Firefox/3.6.15")conn.setRequestProperty("Content-Type","text/html")conn.setRequestProperty("Accept","text/html,application/xhtml xml,application/xmlq=0.9,*/*q=0.8")InputStreamis=conn.getInputStream()BufferedReaderbr=newBufferedReader(newInputStreamReader(is,"GB2312"))Stringline=nullwhile((line=br.readLine())!=null){System.out.println(line)}br.close()returnIP}

js怎么解码被json的数据

解析json数据
var json = {  contry:{ area:{ man:"12万",  women:"10万" } } }
//方式一:使用eval解析  
var obj = eval(json)  
alert(obj.constructor)
alert(obj.contry.area.women)  

//方式二:使用Funtion函数  
var strJSON = "{name:json name}"//得到的JSON  
var obj = new Function("return"   strJSON)()//转换后的JSON对象  
    alert(obj.name)//json name  
    alert(obj.constructor)

//复杂一点的json数组数据的解析  
var value1 = [{"c01":"1","c02":"2","c03":"3","c04":"4","c05":"5","c06":"6","c07":"7","c08":"8","c09":"9"}, {"c01":"2","c02":"4","c03":"5","c04":"2","c05":"8","c06":"11","c07":"21","c08":"1","c09":"12"}, {"c01":"5","c02":"1","c03":"4","c04":"11","c05":"9","c06":"8","c07":"1","c08":"8","c09":"2"}]   var obj1 = eval(value1)  
alert(obj1[0].c01) 

//复杂一点的json的另一种形式  
var value2 = {"list":[ {"password":"1230","username":"coolcooldool"}, {"password":"thisis2","username":"okokok"}], "array":[{"password":"1230","username":"coolcooldool"},{"password":"thisis2","username":"okokok"}]}  

var obj2 = eval(value2)  
alert(obj2.list[0].password)

json数据中有json数组 怎么解析

实例:
import net.sf.json.JSONArray

public class TestJson
{
public static void main(String []args)
{
String json = "[{"a":"111","b":"222","c":"333"},{"a":"1000","b":"2000","c":"000"},{"a":"999","b":"300","c":"700"}]"
JSONArray jsonArr = JSONArray.fromObject(json)
String a[] = new String[jsonArr.size()]
String b[] = new String[jsonArr.size()]
String c[] = new String[jsonArr.size()]
for (int i = 0 i < jsonArr.size() i ) {
a[i] = jsonArr.getJSONObject(i).getString("a")
b[i] = jsonArr.getJSONObject(i).getString("b")
c[i] = jsonArr.getJSONObject(i).getString("c")
}

for (int i = 0 i < c.length i ) {
System.out.print(a[i] " ")
System.out.print(b[i] " ")
System.out.print(c[i])
System.out.println()
}
}
}

安卓中返回的json数据怎么解析

WebService返回的Json字符串或者是XML文件,看你要怎么样用,Android中有解析Json的对象如JSONObject,JsonArray等,着键你的WEBService要配置好。

android 获取了json 类型的数据,怎么解析

JSONObject dataJson=new JSONObject("你的Json数据“)
JSONObject response=dataJson.getJSONObject("response")
JSONArray data=response.getJSONArray("data")
JSONObject info=data.getJSONObject(0)
String province=info.getString("province")
String city=info.getString("city")
String district=info.getString("district")
String address=info.getString("address")
System.out.println(province city district address)

最新文章

随便看看