删除Json中的空白区域

时间:2014-10-31 15:41:40

标签: javascript json

如何删除以下代码块中的空格并存储在javascript变量中?

这是原始格式

{ "info":"First Json",
  "description":"Official Website",
  "timestamp":"1337936081",
   "rates":{
            "USD":"840", 
            "CHF":"1319", 
            "BDT":"298",
            } 
}    

这是我想要的格式

{"info":"Central Bank of Myanmar","description":"Official Website of Central Bank of Myanmar","timestamp":"1337936081","rates":{"USD":"840","CHF":"1319","BDT":"298","SGD":"632","JPY":"1053","GBP":"887","AUD":"759"}}     

1 个答案:

答案 0 :(得分:9)

var jsonWithWhitespaceRemoved = JSON.stringify(JSON.parse(variableWithJsonWhitespace))