{"name": "John", "age": 30, "city": "New York"}
给定以下JSON...
给定以下JSON...
var body = "{ \"name\": \"test\", \"description\": \"test json\", \"website\": \"domain.com\" }"
如何除了值中的空格之外,移除所有的空格?
我尝试了以下正则表达式...
var body = "{ \"name\": \"test\", \"description\": \"test json\", \"website\": \"domain.com\" }".replace(/\r?\n|\r/g, "").replace(/\s+/g, "")
...但它也会删除值中的空格(例如description
):
{"name":"test","description":"testjson","website":"domain.com"}
我需要获取
{"name":"test","description":"test json","website":"domain.com"}
Tx.
JSON.stringify(body)
。 - elclanrsJSON.stringify(body)
返回的是没有空格的字符串。在尝试从中删除空格之前,您是否尝试查看是否存在空格? - zerkms