Json은 모든 캐릭터를 개별 객체로 돌려준다고요?
JSON API 플러그인을 사용하여 워드프레스에서 로드하는 json 객체가 있습니다.json 객체를 로드하고 그 부분을 로그아웃하려고 하면 모든 문자를 고유 객체로 취급하는 것 같아서 루프는 단일 문자인 항목이 포함된 몇 천 개의 객체를 반환합니다.json을 사용하는 것은 처음이라 여기서 한 단계를 놓치고 있는지 모르겠습니다.이것이 지금까지 사용하고 있는 코드입니다.
function getProjInfo(theId){
$.ajax({// calling the ajax object of jquery
type: "GET",// we are going to be getting info from this data source
url: 'http://testing.charter21.com/api/get_post/?post_id='+ theId,//the datasource
dataType: "application/json",
success: function(data){
parseJson(data);
}, // what happens when it is successful at loading the XML
error: function(){
alert("error");
}
});
}//end of the function
function parseJson(inData){
postInfo = inData;
$.each(postInfo, function(index, value){
console.log(this);
});
}
json은 다음과 같습니다.
{
"status": "ok",
"count": 10,
"count_total": 19,
"pages": 2,
"posts": [
{
"id": 175,
"type": "post",
"slug": "home-page-slider",
"url": "http:\/\/testing.charter21.com\/uncategorized\/home-page-slider\/",
"status": "publish",
"title": "Home Page slider",
"title_plain": "Home Page slider",
"content": "<p>The cImages in here are the images that are in the slider on the home page this content in this box will not show up. Its only here as a guide.<\/p>\n",
"excerpt": "The cImages in here are the images that are in the slider on the home page this content in this box will not show up. Its only here as a guide.",
"date": "2011-01-25 10:40:25",
"modified": "2011-01-25 10:40:25",
"categories": [],
"tags": [],
"author": {
"id": 1,
"slug": "admin",
"name": "admin",
"first_name": "",
"last_name": "",
"nickname": "admin",
"url": "",
"description": ""
},
"comments": [],
"attachments": [],
"comment_count": 0,
"comment_status": "open"
}
그래서 기본적으로 "status"를 키로, "ok"를 값으로 주는 대신 json 객체의 모든 문자에 대해 "s"의 값을 가지는 인덱스 0을 가진 객체로 "s"를 얻습니다.이 문제에 대해 어떤 도움이라도 주시면 감사하겠습니다.
설정해야 합니다.dataType:json
jQuery가 JSON 형식의 문자열을 자바스크립트 객체로 변환하여 처리할 수 있도록 $.ajax() 요청에 저장합니다.현재 사용중입니다.application/json
이 값은 mime 형식이며 jQuery 요청에서 이 필드에 대해 유효한 값이 아닙니다.
data = eval(데이터)를 시도할 수 있는 경우, 이 javascript 문은 문자열을 json 개체로 변환해야 합니다.
Jquery 기능을 사용합니다.
data = $.parseJSON(data);
각각 달러를 사용하기 전에
내 각도에서 풀었던 방법.JS 앱은 서버(Node Express를 사용하고 있습니다)의 응답을 문자열이 아닌 자바스크립트 객체로 전송하는 것입니다.다른 건 아무것도 안 통했어요.
var response = {};
response.error = "Error message";
res.send(response);
언급URL : https://stackoverflow.com/questions/4855583/json-returns-every-character-as-a-separate-object
'programing' 카테고리의 다른 글
mysql에서 '!='와 '<>'의 차이점은 무엇입니까? (0) | 2023.10.14 |
---|---|
JDBC vs 안드로이드용 웹 서비스 (0) | 2023.10.14 |
Angular 2 라우터.항법 (0) | 2023.10.14 |
뜻뜻뜻 (0) | 2023.10.14 |
32 대 64 플랫폼 크기의 printf: 플랫폼 독립적인 방식으로 포맷 코드를 처리하려면 어떻게 해야 합니까? (0) | 2023.10.14 |