2017-07-12 6 views
1

を使用。ここにコードは、エラー:無効なJSON私は要求モジュールを使用してデータを投稿しようとしているのNode.js要求モジュール

var requestInfo = { 
     tags: [ 
      { 
       "name": 'UIW_IWIWU', 
       "filters": { 
        "attributes": { 
         "VesselId": '2982' 
        } 
       }, 
       "order": "asc" 
      } 
     ], 
     start: "15mi-ago", 
     end: "30ms-ago" 
    }; 


    request.post({ 
      uri:'http://localhost:3000/data-api', 
      json: 'true', 
      body: requestInfo 
     },function (error, response, body) { 
      res.send(response);   
     } 
    ); 

上記のコードは、JSON無効なエラーを端末にスローします。ここで

Error: Invalid json 

は、スタックトレースです:

Error: invalid json 
    at parse (D:\Working\branches\Smartship-SNG_Demo\node_modules\body-parser\li 
b\types\json.js:83:15) 
    at D:\Working\branches\Smartship-SNG_Demo\node_modules\body-parser\lib\read. 
js:108:18 
    at invokeCallback (D:\Working\branches\Smartship-SNG_Demo\node_modules\raw-b 
ody\index.js:262:16) 
    at done (D:\Working\branches\Smartship-SNG_Demo\node_modules\raw-body\index. 
js:251:7) 
    at IncomingMessage.onEnd (D:\Working\branches\Smartship-SNG_Demo\node_module 
s\raw-body\index.js:307:7) 
    at emitNone (events.js:86:13) 
    at IncomingMessage.emit (events.js:185:7) 
    at endReadableNT (_stream_readable.js:974:12) 
    at _combinedTickCallback (internal/process/next_tick.js:74:11) 
    at process._tickCallback (internal/process/next_tick.js:98:9) 
+1

でなければなりませんそれはのために働きます私も、teminalでもそうです。ノードのバージョン:7.10、それが役立つ場合。 – Lazyexpert

+1

シェアエラースタックトレース。私が思う –

+1

@MukeshSharmaスタックトレース、問題はrequest.post' 'の応答です。 'のhttp:// localhostを:3000 /データapi'は、コンテンツタイプとして'アプリケーション/ json'を設定して、非JSONデータを返すことができます。 – iJade

答えて

0

JSON構造を確認してください

JSONのキーは文字列

更新JSON構造

var requestInfo = {"tags": [{ 

     "name": "UIW_IWIWU", 
     "filters": { 
      "attributes": { 
       "VesselId": 2982 
      } 
     }, 
     "order": "asc" 
    }], 
    "start": "15mi-ago", 
    "end": "30ms-ago" 
} 
関連する問題