在javascript中获取节点后,无法从json获取值
对于我的API GET操作,我使用节点获取,我的代码是在javascript中获取节点后,无法从json获取值,javascript,json,rest,get,node-fetch,Javascript,Json,Rest,Get,Node Fetch,对于我的API GET操作,我使用节点获取,我的代码是 var fetch = require('node-fetch'); const HttpProxyAgent = require('http-proxy-agent'); const HttpsProxyAgent = require('https-proxy-agent'); fetch('https://threemashery.rb.ipdesign.info/cit1/apigw/tibs/nbrmgmt/NumberMana
var fetch = require('node-fetch');
const HttpProxyAgent = require('http-proxy-agent');
const HttpsProxyAgent = require('https-proxy-agent');
fetch('https://threemashery.rb.ipdesign.info/cit1/apigw/tibs/nbrmgmt/NumberManagementService/v1/RetrieveListDNForSelection?apikey=5w8anhcabembfp7tne67rhk8&userID=cpacadm&quantity=2&operatorId=3UK&orderNumber=ORD12341&numberCategory=Normal', {method: 'GET', agent: new
HttpsProxyAgent('http://10.10.104.4:50683') })
.then(resRaw=>{
return resRaw.text();
})
.then(resJson=>{
console.log(resJson);
console.log(resJson.Header);
})
下面是我的两个控制台日志输出
{"Header":{"ActivityName_T":"AS_DNLogicalResource_NM","MsgType_T":"RESPONSE","msgName":"Error occured while processing request for List DN","Source":"RetrieveListDNLogicalResourceNM","ActivityStatusEnum_T":"FAILURE","ActivityStatus_T":"rcFailure","Timestamp":"2018-07-26T14:45:14.009Z","ProviderInfo":[{"name":"b08359a6-dea1-4e34-9c47-8d5971e1a9dd1532616302405","valueType":"rcFailure","description":"Order is being modified.","Value":{"CharacteristicValue":[{"value":"FAILURE"}]}}]},"Payload":{"NotificationDetails":[{"errorCode":"rcFailure","errorDescription":"Order is being modified."}]}}
undefined
为什么当我尝试获取第一个元素时,我会变得如此未定义?有人请帮帮我
甚至我也试过下面的方法
console.log(resJson);
let res=JSON.stringify(resJson);
console.log(res);
let res=JSON.stringify(resJson);
但我越来越
{"Header":{"ActivityName_T":"AS_DNLogicalResource_NM","MsgType_T":"RESPONSE","msgName":"Error occured while processing request for List DN","Source":"RetrieveListDNLogicalResourceNM","ActivityStatusEnum_T":"FAILURE","ActivityStatus_T":"rcFailure","Timestamp":"2018-07-26T14:40:40.189Z","ProviderInfo":[{"name":"4463c84f-4d38-4173-8f11-3b82b2c539a51532616029573","valueType":"rcFailure","description":"Order is being modified.","Value":{"CharacteristicValue":[{"value":"FAILURE"}]}}]},"Payload":{"NotificationDetails":[{"errorCode":"rcFailure","errorDescription":"Order is being modified."}]}}
"{\"Header\":{\"ActivityName_T\":\"AS_DNLogicalResource_NM\",\"MsgType_T\":\"RESPONSE\",\"msgName\":\"Error occured while processing request for List DN\",\"Source\":\"RetrieveListDNLogicalResourceNM\",\"ActivityStatusEnum_T\":\"FAILURE\",\"ActivityStatus_T\":\"rcFailure\",\"Timestamp\":\"2018-07-26T14:40:40.189Z\",\"ProviderInfo\":[{\"name\":\"4463c84f-4d38-4173-8f11-3b82b2c539a51532616029573\",\"valueType\":\"rcFailure\",\"description\":\"Order is being modified.\",\"Value\":{\"CharacteristicValue\":[{\"value\":\"FAILURE\"}]}}]},\"Payload\":{\"NotificationDetails\":[{\"errorCode\":\"rcFailure\",\"errorDescription\":\"Order is being modified.\"}]}}"
为什么当我尝试获取第一个元素时,我会变得如此未定义
您说过return resRaw.text()
所以resJson
是响应的文本
简单字符串没有标题
属性
如果要将响应解析为json并将结果对象放入resJson
,则需要返回resRaw.json()
甚至我也试过下面的方法
console.log(resJson);
let res=JSON.stringify(resJson);
console.log(res);
let res=JSON.stringify(resJson);
这是走错方向了。获取字符串,然后用JSON表示它
您需要将JSON解析为JavaScript数据