如何删除以下代码块中的空格并存储在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"}}
答案 0 :(得分:9)
var jsonWithWhitespaceRemoved = JSON.stringify(JSON.parse(variableWithJsonWhitespace))