我是JavaSript和NativeScript的新手。我能够从API调用中获取JSON字符串。我试图通过JSON.parse解析它,但不幸的是我没有得到任何东西。任何人都可以帮忙吗?
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)
})
}
答案 0 :(得分:2)
使用此
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){
alert(response.username)
})