【发布时间】:2019-06-04 12:21:05
【问题描述】:
我需要从以下格式的传递参数中获取数据,因为在 Postman 中进行测试时,只有这种格式会给出响应。
"json": {"model":"DB11 AMR","modelyear":"2019","locale":"AA"}
请您帮忙从以下服务器 url 获取数据。 https://vhapp.azurewebsites.net/myAMLModelSelection
下面是我的代码
var url = 'http://vhapp.azurewebsites.net/myAMLModelSelection'
try {
let response = fetch(url, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"json" : { "locale": "AA", "model" : "DB11 AMR", "modelyear" : "2019" }
})
})
.then(res => res.text()) // convert to plain text
.then(text => {
console.log(text)
alert(text)
var res = text.substring(1, text.length-2);
var obj = JSON.parse(res);
alert(obj.cars[0].name)
})
.catch((error) => {
console.error(error);
});
} catch (errors) {
console.log(errors);
}
这是我需要的回复
({"cars":[{"name":"DB11 AMR","content":{"guide":"http://cdntbs.astonmartin.com/360ss/OwnersGuides/KY53-19A321-AC. pdf","assets":[{"intAssetId":"115","intVehicleId":"1","strType":"pdf","strName":"附件手册","strDescription":null,"strLocation ":"http://cdntbs.astonmartin.com/360ss/iPad/myaml/brochures/Accessories Brochure English - 706435-PK.pdf","intVersion":"1","intOrder":"1"}]} }]});
【问题讨论】:
标签: react-native