繁体   English   中英

从数组中获取 JSON object 值

[英]Get the JSON object Value from array

我无法将 object 值添加到 html id 输入字段。

JSON 返回

 // response from the call { "COLUMNS": ["cityname", "stateabbr"], "DATA": [ ["Culver City", "CA"] ] } $(document).ready(function() { $("#zipcode").keyup(function() { var el = $(this); if (el.val().length === 5) { $.ajax({ url: 'zipcode.cfc?method=getZipCode&returnFormat=json', type: 'get', data: { zipcode: $("#zipcode").val() }, dataType: 'json', success: function(response, success) { console.log(response); console.log('Ran Successfully'); var i = 0; var col = []; var dat = []; col = response.COLUMNS; dat = response.DATA; console.log('col ', col); console.log('dat ', dat); $.each(response, function(index, zc) { $("#cityname").append([zc[0]]); $("#stateabbr").append([zc[0]]); }); console.log(cityname); console.log(stateabbr); }, error: function(response) { console.log('Error' + response) } }); } }); });

你必须为每个修复。 试试这个

            $("#cityname").val(response.DATA[0][0]);
            $("#stateabbr").val(response.DATA[0][1]);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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