无法通过rest api读取json变量

Cant reading json variables trough rest api

本文关键字:读取 json 变量 api rest      更新时间:2023-09-26

我在通过rest api 读取变量json时遇到问题

问题:
我的儿子
….

"Featured_media":11661,
"Comment_status"、"open"
"Ping_status"、"open"
"地理位置城市":["Oeiras"],
"_links":{
"自我":[{
"Href":"http:''/''/website.com''/wp-json''/wp''/v2''/lists''/11660"
…..

我可以用这个代码读取所有变量less geolocation_city

        $.getJSON('http://imaginocharme.com/wp-json/wp/v2/listings/11660', function (jd) {
        $('#stage').html('<p> Nome: ' + jd.featured_media + '</p>');
        console.log(jd.featured_media);
        $('#stage').append('<p>Descrição : ' + jd.comment_status + '</p>');
        console.log(jd.comment_status);
        $('#stage').append('<p>Nome : ' + jd.ping_status + '</p>');
        console.log(jd.ping_status);
        $('#stage').append('<p>Cidade : ' + jd.geolocation_city + '</p>');
        console.log(jd.geolocation_city);
        $('#stage').append('<p>Links : ' + jd._links.self[0].href + '</p>');
        console.log(jd._links.self[0].href);
           }); 


我的控制台日志

11661
index.html (29,29)
open
index.html (31,29)
open
index.html (33,29)
undefined
index.html (35,29)
http://imaginocharme.com/wp-json/wp/v2/listings/11660
index.html (37,29)


我尝试了几种方法来读取变量geolocation_city,并且总是给出未定义的

有人能帮忙吗
知道吗

jd.geolocation_city是一个数组,这就是为什么不显示它的原因。试试这个:
jd.geolocation_city.toString()