내가 생성한 웹 응용 프로그램을 사용하는 이동을 서버에 데이터를 제공하게 반응하는 앱입니다.
의 건축에서 나 server,나를 따라 제공하는 튜토리얼에 의해 이동 문서(https://golang.org/doc/tutorial/web-service-gin). 내 코드와 매우 유사하는 코드,그리고 내가 예상 결과를 얻을 사용하면 컬.
[
{
"id":0,
"date":"2021-11-21T12:00:00Z",
"rentedTo":"Bob",
"rentedBy":"Jim"
},
//etc...
내가 사용하는 경우 반응의 가 API,그러나,나의 결과에 다시 와서 예기치 않은 형태입니다.
fetch('http://localhost:8080/rentals')
.then((response)=> {
if (response.ok) {
return response.json();
}
throw response;
.then((jsonArr) => {
handleRentalsData(jsonArr)
})
.catch((error) => {
console.error("Error fetching data: ", error);
});
을 때 나 console.log(jsonArr)
브라우저에 보고서를 다음과 같다:
Array(3) [ {...},{...},{...} ]
//Expanding this object via the console shows the following information:
---> 0: Object { id: 0, date: "2021-11-21T12:00:00Z", rentedTo: "Bob", ... }
---> 1: Object { id: 1, date: "2021-11-22T12:00:00Z", rentedTo: "Bob", ... }
---> 2: Object { id: 2, date: "2021-11-23T12:00:00Z", rentedTo: "Bob", ... }
이러한 지표(그리고 브라우저 상표)표시된 데이터를 형태로 지금의 배열을,그래서 처리했습니다.
내가 하려고 했을 통해 루프 이 배열을 분석하 json 문자열의 내부는 그지만, JSON.parse(data)
생산 숫자만(0,1,2 각각)보다는 생체로,이메일 주소와 비밀번호를 입력해.
for (const json in jsonArr){
console.log(typeof json); //string
const rentalObj = JSON.parse(json);
console.log(typeof rentalObj); //number
console.log(rentalObj); //0, 1, and 2 respectively
console.log(rentalObj.date); //undefined, because rentalObj is now a number.
}
나는 몇 가지를 찾고,들어 있는 인덱스는 배열의 데이터에 와서 일으킬 수 있는 문제,그래서 나는 시도하는 분석과 함께 자극성능,뿐만 아니라.
for (const json in jsonArr){
console.log(typeof json); //string
const rentalObj = JSON.parse(json, (key, value) => {
console.log(key); //<empty string>
console.log(value); //0, 1, and 2
return(value);
});
console.log(typeof rentalObj); //number
console.log(rentalObj); //0, 1, and 2 respectively
console.log(rentalObj.date); //undefined
}
도 JSON.parse(jsonArr)
오류가 발생으로 예상된다. 나에 부딪쳤습니다. 왜 분석으로(n index)번호? 어떻게 추출할 수 있는 객체의 내부에 배열할 때,구문 분석(또는 인쇄)문자열의 내부에 배열을 생산 숫자만?