我是json,js等新手 所以我对这一切有点困惑,httprequests等。 我试图从响应中提取数据。首先我做了XMLHttpRequest,但是我在这里阅读了Stackoverflow,最好使用像jquery或类似的框架,并且由于我已经使用jquery mobile,所以感觉很自然。Http请求,提取数据
现在的问题是如何从“响应”中获取数据。
XMLHttpRequest.response文字是这样的:
{"list":null,"data":{"id":95,"picture":"/content/picture/icons/Rome","text":"En galning hældte forleden 1 ton sukker i Roms officielle vandforsyning","appId":1,"textHeader":"Rome sweet Rome!!","localAction":"url(http://www.b.dk)","sortOrder":0,"lastCheck":null},"expires":2592000000,"server":null}
,现在当我想跟着从jquery的例子中,我得到一个对象返回。但没有在数据*
其代码:
var startUrl = "http://localhost:8080";
function httpGet(theUrl)
{
$.getJSON(startUrl+theUrl,
function(data){
alert(data);
$.each(data.items, function(i,item){
alert(i+item);
});
});
}
如何把我的代码出来的吗?
你如何从你的代码中得到什么? – shxfee
首先你的回应中没有.items,这是你没有看到任何东西的原因。你可以使用“data。*”来访问对象属性。从repsonse用法获取id的示例:data.data.id; – xdevel
[this](http://stackoverflow.com/questions/2487841/jquery-parse-json-multidimensional-array)可能会帮助你。 – Jebin