我有一个 JSON 对象,我想在代码镜像中显示它。代码镜像只需要字符串。当我做 JSON.stringify 它搞砸了它是一个数组而不是字符串的值。
例如。这是 JSON.stringify 的输出
{
"version": "1.1",
"sid": "ManagementService",
"svcVersion": "0.1",
"oid": "getCurrentStatsForServiceTypes",
"params": {
"serviceTypes": "[\"rest\", \"wsdl\", \"database\", \"rss\"]"
}
}
我想要输出为...
{
"version": "1.1",
"sid": "ManagementService",
"svcVersion": "0.1",
"oid": "getCurrentStatsForServiceTypes",
"params": {
"serviceTypes":["rest", "wsdl", "database","rss"]
}
}
简而言之,我想在不影响值的情况下将 Type 从 Object 转换为 String。
更新:JSON 对象是
{
"version": "1.1",
"sid": "ManagementService",
"svcVersion": "0.1",
"oid": "getCurrentStatsForServiceTypes",
"params": {
"serviceTypes":["rest", "wsdl", "database","rss"]
}
}
我想要和字符串一样。像这样的东西应该工作。
'{
"version": "1.1",
"sid": "ManagementService",
"svcVersion": "0.1",
"oid": "getCurrentStatsForServiceTypes",
"params": {
"serviceTypes":["rest", "wsdl", "database","rss"]
}
}'
块引用