简体   繁体   中英

Passing dynamic value in Json object

i am new in Json/JS, Could you help telling how to pass aa value from js var to Json object as in below case:

var ad_id = JSON.stringify(Adv.get({"name":"Abc"}));
console.log(ad_id);

O/P is correct - {"incomplete":false,"list":[{"id":1303,"name":"Ad9023"}]}

Now here I need to extract value of id and pass it to below command

console.log(JSON.stringify(As.put({"ad_id":ad_id.id,"name":"A9023"})));

O/PI am getting is - Response 200 received

{"incomplete":false,"error":[{"code":10,"jpath":"$.ad_id","message":"Val
ue cannot be null or missing."}]}

I assume you want

var getVar = JSON.stringify(Adv.get({"name":"Abc"}));

var putVar = { "ad_id":getVar.list[0].id,"name":getVar.list[0].name};
console.log(JSON.stringify(As.put(putVar)));

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