0
데이터를 JSON URL에서 가져 오려고합니다. 내 데이터가 JSON 배열 내에 배열되어 있습니다. 여기서는 꽤 새롭기 때문에 제게 데이터를 읽는 방법을 제안 해주세요. 고마워요. . 여기 null의 속성 'length'을 읽을 수 없습니다.
아약스 결과의 성격에 대해 아무 생각이없는 내 코드 .. 내가 오류가 JSON에서 값을 읽을의 시간에<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Privacy Policy</title>
</head>
<body>
<div id="showdata"></div>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script>
$(function(){
var url = "http://portal.entitledirect.com/test/entitle_news.php";
var data = {"news_type": "docs","dt":"1417222458109"};
$.ajax({
url: url,
data:data,
dataType: "jsonp",
contentType: 'application/json',
type: 'GET',
jsonpCallback: 'methodCaa',
success: function (result) {
console.log(result);
$.each($.parseJSON(result), function (item, value) {
if (item == "rates") {
$.each($.parseJSON(value), function (i, object) {
console.log(i + "=" + object);
});
}
});
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(jQuery.parseJSON(jqXHR));
console.log(textStatus); console.log(errorThrown);
}
});
});
function methodCaa(data){
console.log((data));
}
</script>
</body>
</html>
...
Uncaught TypeError: Cannot read property 'length' of nulljquery-1.7.1.min.js:2 e.extend.eachjsonindex.html:25 $.ajax.successjquery-1.7.1.min.js:2 njquery-1.7.1.min.js:2 o.fireWithjquery-1.7.1.min.js:4 wjquery-1.7.1.min.js:4 d.onload.d.onreadystatechange
이의 구조를 게시하세요'result' ... –
@krillgar jQuery를 내부적으로 사용 할 수 ... –
는'$ .parseJSON을()'사용하지 마십시오; 결과는 이미 구문 분석됩니다. – JJJ