在将Json String发布到StackOverflow之前格式化Json String的最简单方法是什么?
我不想手动格式化,大多数在线网站只验证Json但不格式化。
自:
[{"lines":{"0": "Hammersmith & City","1": "Circle"},"id": "233","name": "Shepherd's Bush Market"},{"lines": {"0": "Hammersmith & City","1": "Circle"},"id": "233","name": "Shepherd's Bush Market"},{"lines": {"0": "Hammersmith & City","1": "Circle"},"id": "233","name": "Shepherd's Bush Market"}]
我想这样做:
[{
"lines": {
"0": "Hammersmith & City",
"1": "Circle"
},
"id": "233",
"name": "Shepherd's Bush Market"
},
{
"lines": {
"0": "Hammersmith & City",
"1": "Circle"
},
"id": "233",
"name": "Shepherd's Bush Market"
},
{
"lines": {
"0": "Hammersmith & City",
"1": "Circle"
},
"id": "233",
"name": "Shepherd's Bush Market"
}]
谢谢,
[编辑]
没有java的引用,但这个问题对于java(Android)开发人员来说是实际的
答案 0 :(得分:3)
我看到很多基于Json解析的问题。
用户发布Json的一些问题:
或在一行中,如:
[{"lines":{"0": "Hammersmith & City","1": "Circle"},"id": "233","name": "Shepherd's Bush Market"},{"lines": {"0": "Hammersmith & City","1": "Circle"},"id": "233","name": "Shepherd's Bush Market"},{"lines": {"0": "Hammersmith & City","1": "Circle"},"id": "233","name": "Shepherd's Bush Market"}]
或尝试手动格式化Json字符串,如:
[{"lines":{"0": "Hammersmith & City","1": "Circle"},
"id": "233","name": "Shepherd's Bush Market"},
{"lines": {"0": "Hammersmith & City","1": "Circle"},
"id": "233","name": "Shepherd's Bush Market"},
{"lines": {"0": "Hammersmith & City","1": "Circle"},
"id": "233","name": "Shepherd's Bush Market"}]
令人遗憾的是,当用户无法解决问题只是因为Json字符串格式不好而且他不知道是Array还是Object。
无论如何使用Notepad++
JSON viewer
安装并重启Notapad ++
完成后,您可以格式化Json,例如:
现在您已经格式化了Json,并准备将其发布到您的问题中。
[{
"lines": {
"0": "Hammersmith & City",
"1": "Circle"
},
"id": "233",
"name": "Shepherd's Bush Market"
},
{
"lines": {
"0": "Hammersmith & City",
"1": "Circle"
},
"id": "233",
"name": "Shepherd's Bush Market"
},
{
"lines": {
"0": "Hammersmith & City",
"1": "Circle"
},
"id": "233",
"name": "Shepherd's Bush Market"
}]
答案 1 :(得分:1)
Google Chrome有一个名为JSON Formatter
的非常好的扩展程序,可将json string
格式化为实际json
格式。它还会告诉您JSON
字符串中是否有错误。
这是link
答案 2 :(得分:1)
JSONEditorOnline完美地完成了这个伎俩。你必须确保你的JSON是有效的,但是网站会告诉你它什么时候没有(是的,其他一些格式化程序网站不能正常工作没有告诉你为什么当JSON无效时)
答案 3 :(得分:0)
您可以尝试使用Formatter JSON,这是一款功能强大的工具,可以验证并使您的JSON更漂亮。