我需要帮助将此 json 字符串转换为 javascript 数组。
我试过这样的事情:
var cityState = $.map(source, function (value) { return value; });
其中“source”是这个 ajax 调用的结果:
$.ajax({
url: 'http://localhost:49858/Default.aspx/getstuff',
dataType: 'json',
type: "POST",
data: "{}",
contentType: "application/json; charset=utf-8"
}).done(function (source) { ...
但它只是无法正常工作。
{"query": "Unit","suggestions":[{"value":"FAIRFIELD, CONNECTICUT","data":"FAIRFIELD, CONNECTICUT"},{"value":"LONG BEACH, CALIFORNIA","data":"LONG BEACH, CALIFORNIA"},{"value":"NEW YORK, NEW YORK","data":"NEW YORK, NEW YORK"},{"value":"HONOLULU, HAWAII","data":"HONOLULU, HAWAII"},{"value":"KANSAS CITY, MISSOURI","data":"KANSAS CITY, MISSOURI"},{"value":"SAN JOSE, CALIFORNIA","data":"SAN JOSE, CALIFORNIA"},{"value":"SOUTH LAKE TAHOE, CALIFORNIA","data":"SOUTH LAKE TAHOE, CALIFORNIA"},{"value":"LAKE DALLAS, TEXAS","data":"LAKE DALLAS, TEXAS"},{"value":"BROOMFIELD, COLORADO","data":"BROOMFIELD, COLORADO"},{"value":"BROOMFIELD, COLORADO","data":"BROOMFIELD, COLORADO"}]}
console.log(source) 的屏幕截图显示: