简体   繁体   中英

VueJS Json file with Api

I have a json value like

{
"T1" : "online",
"T2" : "offline"
}

And there is an online API which send me just

{
StatusCode :"T1"
}

I need a way to get the code from API then compare it with my local json file and print the value in input field ( not drop-down )

The question is not very clear but if I understand correct you want to get the value from the first object depending on the status code you get from the api. In this case you need to:

Turn the json into an object, use JSON.parse()

let a = {"T1": "online", "T2": "offline"};
let b = {StatusCode: "T1"};  

you will be able to access the variable like so:

a[b.StatusCode];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM