0
제 3 자 API를 사용하여 JSON 객체를 반환하고 있습니다.JSON 객체가 반환하지 않음
category:
{
"sys":
{
"id":"44uyBvGjFmsmoU6uqiiSOq",
"revision":1,
"type":"Entry",
"locale":"en-US",
"contentType":
{
"sys":
{
"id":"2V5tBa4wf6cuMSIu4McuUc",
"type":"Link",
"linkType":"ContentType"
}
},
"createdAt":"2014-09-13T22:40:39.901Z",
"updatedAt":"2014-09-13T22:40:39.901Z",
"space":
{
"sys":
{
"id":"t667fybp3v46",
"type":"Link",
"linkType":"Space"
}
}
},
"fields":
{
"name":"birth control"
}
}
하지만 다음을 사용하여 변수를 시도하고 액세스 할 때, 나는 점점 계속 : 내가 변수를 인쇄 할 때 나는 다음과 같은 얻을 "아마도 처리되지 않은 형식 오류를 : 정의되지 않은의 '이름'속성을 읽을 수 없습니다"
if (o.fields.category)
{
var str = JSON.stringify(o.fields.category, undefined, 2);
console.log(str);
var json_category = JSON.parse(str);
// console.log("--------------Category for the resource: " + o.fields.category);
$.each(json_category, function(index, object){
alert(10);
var category = {};
// console.log("--------------Category for the resource: " + object.sys);
category.id = object.sys.id;
// console.log("--------------Category for the resource: " + object.fields.name);
category.name = object.fields.name;
// console.log("--------------Category for the resource: " + object.sys.updatedAt);
category.updatedAt = object.sys.updatedAt;
categories.push(category);
});
}
모든 도움을 주시면 감사하겠습니다.
이 API에 대한 호출은 어떻게 생겼습니까? 문제는 API가 비동기 적이기 때문에 결과를 제대로 기다리지 못하는 것일 수 있습니다. – Pointy
저는 Contentful과 Javascript 라이브러리를 사용하고 있습니다. https://www.contentful.com/developers/documentation/content-delivery-api/ – zee
오, 무슨 일이 일어나는지 봅니다. – Pointy