[{},{}]怎么转换成json

时间:2023-01-23 14:22:58
例如:有这样的字符串[{"CityId":18,"CityName":"西安","ProvinceId":27,"CityOrder":1},{"CityId":53,"CityName":"广州","ProvinceId":27,"CityOrder":1}],用js转换成json对象,请高手指导
var data;
var json='[{"CityId":18,"CityName":"西安","ProvinceId":27,"CityOrder":1},{"CityId":53,"CityName":"广州","ProvinceId":27,"CityOrder":1}]';
eval("data="+json);
alert(data);



$.post(
   root_path + "/om_center/request/get_result",
   put_json,
   function(data){
    //var obj_json = eval("(" + data + ")");
    var obj_json;
    eval("obj_json="+data);
    
    //var obj_json = eval("(" + '{"id":"01","request_name":"requestlink","login_id":"8615196692960","result":"success","Date":"2015.08.19","information":""}' + ")");
    //alert(obj_json.id);
    var html = '<tr>'                                  +
                '<th class="table_id">ID</th>'                     +
                '<th class="table_request_name">Request name</th>' +
                '<th class="table_login_id">Login ID</th>'         +
                '<th class="table_result">Result</th>'             +
                '<th class="table_date">Date</th>'                 +
                '<th class="table_infomation">Information</th>'    +
            '</tr>';

    /**
     * 处理json日志
     */
    for(var i=0; i<obj_json.length; i++) {
     var obj = obj_json[i];
//     alert(obj.id);
//     alert(obj.request_name);
//     alert(obj.login_id);
    html +=
     "<tr>" +
      "<td>" + obj.id           + "</td>"  +
      "<td>" + obj.request_name +"</td>"   +
      "<td>" + obj.login_id     +"</td>"   +
      "<td>" + obj.result       +"</td>"   +
      "<td>" + obj.Date         + "</td>"  + 
      "<td>" + obj.information  +"</td>"   +
     "</tr>"
    //);
   }