PhoneGap GetJson奇怪的输出 - REST

时间:2014-07-20 17:36:03

标签: json rest debugging cordova getjson

我遇到这种情况:(我公开的测试网站)

  $.getJSON("http://ee-tutz.com/entry_api/rest/read_entry/json?auth[username]=test&auth[password]=guest&data[entry_id]=80",function(data){
        alert(data); // here i get [obj Obj]
       var tweetlistHTML = "";
        for(var i = 0; i< data.results.length;i++){
            tweetlistHTML +='<li>'+data.results[i].title+ '</li>'
        }
        var tweetList = $("#tweetlist");
        tweetList.html(tweetlistHTML);
    });

有什么问题吗? 我想输出一些从URL得到的数据(例如标题) 但它Doesen输出标题

1 个答案:

答案 0 :(得分:2)

您可以尝试使用JSON.stringify()方法输出对象详细信息 这会让您知道返回的object propertiesvalues 例如警告第一个对象详细信息。

alert(JSON.stringify(data.results[0]));

或者数组中的整个对象。

alert(JSON.stringify(data.results));

您是否也尝试从桌面浏览器检查结果是否URL返回JSON响应 的 EDIT1: 我刚检查了URL的响应 您需要更改数据变量语法。

data.data[i].title

而不是

data.results[i].title

<强> EDIT2: 哎呀。我忘记更改警报代码了 警报应该是。

alert(JSON.stringify(data.data[0]));

或者您可以提醒整个数据。

alert(JSON.stringify(data));

<强> EDIT3:
您返回的JSON数据 http://ee-tutz.com/entry_api/rest/read_entry/json?auth[username]=test&auth[password]=guest&data[entry_id]=80
JSON数据:

{"message":"Successfully readed","code":200,"code_http":200,"data":[{"entry_id":"80","site_id":"1","channel_id":"1","author_id":"1","forum_topic_id":null,"ip_address":"86.120.164.135","title":"POP ON OP: an Interactive Real-Time Animation Object-Book","url_title":"pop-on-op-an-interactive-real-time-animation-object-book","status":"open","versioning_enabled":"y","view_count_one":"0","view_count_two":"0","view_count_three":"0","view_count_four":"0","allow_comments":"y","sticky":"n","entry_date":"1405812194","year":"2014","month":"07","day":"20","expiration_date":"0","comment_expiration_date":"0","edit_date":"20140719233024","recent_comment_date":"0","comment_total":"0","main_content":"POP ON OP is an interactive real-time animation object-book in which you can experience movement directly on paper with a special film.","propietati":"74%$23,959 Funded &nbsp; ","testfisier":false,"poza":"<img alt=\"Photo little\" class=\"fit\" height=\"150\" src=\"https:\/\/s3.amazonaws.com\/ksr\/projects\/1055334\/photo-little.jpg?1404412397\" width=\"200\" \/>","descriere":" POP ON OP is an interactive real-time animation object-book in which you can experience movement directly on paper with a special film. ","autor":"  by PARRATORO  ","categories":[]}],"id":"80"}