-3
我是JavaSript和NativeScript的新手。我可以从API调用中获取JSON字符串。我试图解析通过JSON.parse它,但不幸的是我没有得到任何东西。任何人都可以帮助吗?如何从Javascript中检索JSON数据
exports.signIn = async function() {
await fetchModule.fetch(apiurl,{
method:"POST",
body:JSON.stringify({"username":username ,"password":password}),
headers: {
"Content-Type": "application/json"
}
}).then(function(response){
var result = JSON.parse(response)
alert(result.username)
})
}
太少的信息。请发布数据示例 –
您尝试过什么?你卡在哪里?我们不想只向您提供解决方案;我们希望你获得谅解。但是,因为我们不知道你的根本问题是什么,所以我们不能开始提供帮助。有关提问的提示,请参见[如何提问](https://stackoverflow.com/help/how-to-ask)。 – Cerbrus
如果你传递了一个json对象,为什么你需要解析它?你是否在http请求中包含'.map(res => res.json())'? – mast3rd3mon