JSON을 완전히 구문 분석 할 수 없습니다. 일부 구문 분석 후 동일한 위치에서 충돌했습니다.

조와 르 5002

"Sponsorship"- "impression_urls"까지 올바르게 구문 분석되지만 그 후에 충돌이 발생합니다. 내가 뭘 잘못하고 있니.? 나는이 플랫폼을 처음 사용합니다. 도와주세요.

//  Code start//



        const express = require("express");
        const bodyParser = require("body-parser");
        const https = require("https");
        const app = express();
        app.use(bodyParser.urlencoded({extended: true}));


        app.get("/", function(req, res) {        
          res.sendFile(__dirname + "/index.html");

          const url = "https://api.unsplash.com/photos/?client_id= my clinet id  is given here";

          https.get(url, function(response) {
            console.log(response.statusCode);
            response.on("data", function(data) {
              const unspalshData = JSON.parse(data);
              console.log(unspalshData.created_at);
    });
  });
});

// 코드 끝 //

일부 구문 분석 후 출력이 중단되었습니다. 아래와 같이-

// 출력 시작 //

[nodemon] starting `node app.js`
server is running in port 3000
200
undefined:1
[{"id":"bXfQLglc81U","created_at":"2020-07-01T18:30:13-04:00","updated_at":"2020-07-07T01:16:02-04:00","promoted_at":null,"width":6016,"height":4016,"color":"#1A1519","description":null,"alt_description":"macbook pro on brown wooden table","urls":{"raw":"https://images.unsplash.com/photo-1593642533144-3d62aa4783ec?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjE0NzI5Nn0","full":"https://images.unsplash.com/photo-1593642533144-3d62aa4783ec?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NzI5Nn0","regular":"https://images.unsplash.com/photo-1593642533144-3d62aa4783ec?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjE0NzI5Nn0","small":"https://images.unsplash.com/photo-1593642533144-3d62aa4783ec?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NzI5Nn0","thumb":"https://images.unsplash.com/photo-1593642533144-3d62aa4783ec?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=200&fit=max&ixid=eyJhcHBfaWQiOjE0NzI5Nn0"},"links":{"self":"https://api.unsplash.com/photos/bXfQLglc81U","html":"https://unsplash.com/photos/bXfQLglc81U","download":"https://unsplash.com/photos/bXfQLglc81U/download","download_location":"https://api.unsplash.com/photos/bXfQLglc81U/download"},"categories":[],"likes":50,"liked_by_user":false,"current_user_collections":[],"sponsorship":{"impression_urls":
SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at IncomingMessage.<anonymous> (C:\jowar_drive\Web_dev_bootcamp\Practise web dev\unspalshAPI\app.js:28:33)
    at IncomingMessage.emit (events.js:315:20)
    at addChunk (_stream_readable.js:295:12)
    at readableAddChunk (_stream_readable.js:271:9)
    at IncomingMessage.Readable.push (_stream_readable.js:212:10)
    at HTTPParser.parserOnBody (_http_common.js:132:24)
    at TLSSocket.socketOnData (_http_client.js:469:22)
    at TLSSocket.emit (events.js:315:20)
    at addChunk (_stream_readable.js:295:12)
[nodemon] app crashed - waiting for file changes before starting...

// output end //
지 슈누 사하

귀하의 게시물에 따라 JSON 문자열이 잘못된 것 같습니다. 필수 중괄호로 끝나지 않기 때문입니다. 따라서 JSON은 불완전하지 않으며 파싱이 오류를 제공하는 이유입니다.

""}}] 를 추가하면 JSON 문자열 끝에 중괄호와 따옴표가 붙습니다. 작동합니다. 하지만 API에서이 불완전한 JSON을 어떻게 얻는 지 궁금합니다. API의 전체 응답을 제공 할 수 있다면 더 도움이 되겠지만 게시 한 JSON에 따라 제 답변을주었습니다. 아래 스크린 샷을 확인하세요.

여기에 이미지 설명 입력

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관