const http = require('http');
const request = http.get('http://localhost:90/rentflig/ajaxfetchproperties.php', response => {
console.log(response.statusCode);
let body = "";
response.on('data', data => {
body += body.toString();
});
response.on('end',() => {
var getData = JSON.parse(body);
console.log(getDate.LocationName);
});
});
0
A
回答
-1
你的意思是data.toString()
:
response.on('data', data => {
body += data.toString();
});
0
其实你在哪里相当接近,但有一些缺件在你的代码
let body = [];
request.on('data', (chunk) => {
body.push(chunk);
}).on('end',() => {
body = Buffer.concat(body).toString();
// at this point, `body` has the entire request body stored in it as a string
const json = JSON.parse(body);
console.log(json);
});
+0
明白了。非常感谢。 – Emmanuel
+0
很高兴帮助@Emmanuel –
相关问题
- 1. 意外的JSON输入结束node.js jason.parse()
- 2. json输入意外结束
- 3. JSON输入的意外结束Angular 2(4)http获取请求
- 4. Gulp:SyntaxError:意外的JSON输入结束
- 5. 意外的输入结束(javascript和JSON)
- 6. SyntaxError:意外的JSON输入结束
- 7. 简单的POST请求到node.js的响应“意外的输入结束”消息
- 8. JSON意外结束
- 9. JSON输入的意外结束,而解组结构
- 10. 来自ajax调用的JSON输入的意外结束
- 11. 意外结束时发送POST请求
- 12. -JSON值失败。错误是:意外的输入结束
- 13. 未捕获(承诺)SyntaxError:意外的JSON输入结束
- 14. $ .ajax()返回语法错误:意外的JSON输入结束
- 15. 转:JSON输入的意外结束和json.Unmarshal返回nil值
- 16. Oracle APEX:错误:SyntaxError:意外的JSON输入结束
- 17. AJAX返回错误JSON输入的意外结束
- 18. Javascript错误:SyntaxError:意外的JSON输入结束
- 19. angular 2 http post方法意外的JSON输入结束
- 20. 无法第二次读取json文件:“意外的输入错误结束”
- 21. 我如何解决'未捕获的SyntaxError:意外的JSON输入结束'错误
- 22. JSON输入意外结束 - 阿贾克斯
- 23. jfrog cli ssh authentication [错误:] JSON输入意外结束
- 24. 输入意外结束(JS)
- 25. JSON + Node.js - 意外的令牌
- 26. 阵营原生取“POST”请求投掷“语法错误:JSON输入意外结束”,在Android的
- 27. “[语法错误:输入意外结束]” 使用Express的Node.js的
- 28. 解压文件时出现文件错误意外结束node.js
- 29. 意外结束JSON输入错误中使用访问令牌在反应原生API在发布请求
- 30. 意外的令牌}在json响应结束时
非常感谢。现在解决了。 – Emmanuel