Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 解析JSON文件中的问题_Jquery_Json - Fatal编程技术网

Jquery 解析JSON文件中的问题

Jquery 解析JSON文件中的问题,jquery,json,Jquery,Json,stackoverflow中给出了一个在jquery中读取jsonp请求的示例。下面的代码工作正常 $(document).ready(function() { var url = "http://api.twitter.com/1/statuses/user_timeline/codinghorror.json"; $.getJSON(url + "?callback=?", null, function(tweets) { for(i in tweets) {

stackoverflow中给出了一个在jquery中读取jsonp请求的示例。下面的代码工作正常

$(document).ready(function() {
   var url =  "http://api.twitter.com/1/statuses/user_timeline/codinghorror.json";
   $.getJSON(url + "?callback=?", null, function(tweets) {
    for(i in tweets) {
        tweet = tweets[i];
        $("#tweet-list").append(tweet.text + "<hr />");
    }
   });
});
$(文档).ready(函数(){
变量url=”http://api.twitter.com/1/statuses/user_timeline/codinghorror.json";
$.getJSON(url+“?回调=?”,null,函数(tweets){
对于(我在推特中){
tweet=tweets[i];
$(“#推特列表”).append(tweet.text+“
”); } }); });
我将json文件上传到一个临时Web服务器中,url为

但是我的json似乎没有被解析,浏览器也没有显示任何错误/警告

任何帮助。

您的代码按原样工作:


但是,从临时Web服务器返回的json是json而不是JSONP。如果您希望以JSON格式请求,请删除
?回调=?
,但这意味着您的临时Web服务器需要与发出请求的页面位于同一个域中。

感谢您的回复kevin..但我希望请求采用jsonp格式,而不是JSON。。它基本上就是我上传的同一个文件,我想做与codinghorror.json相同的操作。那么你不能用flat.json文件来做。您需要一种服务器端语言来解释?callback参数并相应地返回jsonp。很抱歉我的无知,但是为什么。。因为它可能不是平面文件,所以即使是平面文件也可以工作。一个简单的文件不能接受
?callback=foo
并用
foo(jsonhere)