2015-09-09 79 views
0

我有一些JSON,看起來像這樣:如何在Javascript中隱藏JSON?

'"geocoded_waypoints" : [ 
    { 
    "geocoder_status" : "OK", 
    "partial_match" : true, 
    "place_id" : "ChIJ7_V-Dou62YgRXjw0MYaotfs", 
    "types" : [ "locality", "political" ] 
    }, 
    { 
    "geocoder_status" : "OK", 
    "partial_match" : true, 
    "place_id" : "ChIJRZdD6h5-1YcR_rYaYBXzk9E", 
    "types" : [ "locality", "political" ] 
    } 

而且我希望它被解析爲普通JSON。我怎樣才能使用JavaScript做到這一點?

+4

's.replace(/ " /克,「')' – dandavis

+0

是有一些方法來取消轉義它 – RadleyMith

+1

修復任何代碼生成的JSON產生用實際的雙引號糾正JSON。 –

回答

1

我會做這樣的:

try{ 
    var mygoodJson = JSON.parse(badJson.replace(/"/g,'"');); 
    }catch(e){ 
    throw e; 
    }