使用 Sepomex 根据邮政编码输入自动填充州和城市 API

Autofill state and city based on zip code input using Sepomex API

我正在尝试使用 sepomex API(对于墨西哥)在基于 javascript 的 corvid 网站上使用 sepomex API(墨西哥)自动填充城市和州字段,但我认为json.response[0]["ciudad"].

行有问题
$w.onReady(function () {
    $w("#input1").onInput(() =>{
    let zipcode = $w("#input1").value;
    $w("#input2").value = "";
    $w("#input3").value = "";

    if (zipcode.length === 5) {
        let apiUrl = "";

        apiUrl = "https://api-sepomex.hckdrk.mx/query/info_cp/";

            fetch(apiUrl + zipcode, {method: 'get'})
            .then((httpResponse) => {
                if (httpResponse.ok) {
                    return httpResponse.json();
                }
                else{
                    return Promise.reject("fetch was not successful")
                }
            })
            .then((json) => {
                console.log(json);
                let response = json.response;

                $w("#input10").value = json.response[0]["ciudad"];
                $w("#input11").value = json.response[0]["estado"];
                
                $w("#text148").collapse();
            })
            .catch(() =>{
                $w("#text148").expand()

            })
}
})

我无法显示任何数据 API

上有输出
[
    {
        "error": false,
        "code_error": 0,
        "error_message": null,
        "response": {
            "cp": "44110",
            "asentamiento": "Vallarta Poniente",
            "tipo_asentamiento": "Fraccionamiento",
            "municipio": "Guadalajara",
            "estado": "Jalisco",
            "ciudad": "Guadalajara",
            "pais": "México"
        }
    }
]

将第二个承诺中的代码更改为。

.then((json) => {
                
 let response = json[0].response;
 
 $w("#input10").value = response.ciudad;
 $w("#input11").value = response.estado;
              
 $w("#text148").collapse();
})

现在它应该可以工作了

已解决

.then((json) =>{
            
            let response = json[0].response;
            

            $w("#input11").value = json[0].response["ciudad"];
            $w("#input10").value = json[0].response["estado"];
            $w("#text148").collapse();
})