如何在Javascript中从JSON中检索数据

时间:2017-09-07 07:32:10

标签: javascript nativescript

我是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)
})

}

1 个答案:

答案 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)
})
相关问题