这个很棒的codebeautify几乎满足了我的需求,但是没有转义特殊字符并使用单引号。对于JavaScript来说似乎还可以。
有没有工具可以将JSON有效负载a转换为多行转义的Java字符串?
我想产生这样的东西:
"{\r\n" +
"\"AttributeLogicalName\": \"entityLogicalname\",\r\n" +
"\"EntityLogicalName\": \"entity\",\r\n" +
"\"Value\": \"100000002\",\r\n" +
"\"Label\": {\r\n" +
"\"LocalizedLabels\": [\r\n" +
"{\r\n" +
"\"Label\": \"nerd\",\r\n" +
"\"LanguageCode\": 1033,\r\n" +
"\"IsManaged\": false,\r\n" +
"\"MetadataId\": \"881daca2-5c68-e911-a825-000d3a1d501d\",\r\n" +
"\"HasChanged\": null\r\n" +
"}\r\n" +
"],\r\n" +
但是codebeautify只产生这个。
' { ' +
' "AttributeLogicalName": "new_localoptionsettoform", ' +
' "EntityLogicalName": "cr965_testcdsentity", ' +
' "Value": "100000002", ' +
' "Label": { ' +
' "LocalizedLabels": [ ' +
' { ' +
' "Label": "nerd", ' +
' "LanguageCode": 1033, ' +
' "IsManaged": false, ' +
' "MetadataId": "881daca2-5c68-e911-a825-000d3a1d501d", ' +
' "HasChanged": null ' +
' } ' +
' ], ' +
答案 0 :(得分:1)
您可以在IntelliJ IDEA中执行此操作。
将您的JSON复制到格式化程序以对其进行格式化,以使其看起来很漂亮,而不是单行:
[
{
"_id": "5cc3f7e46a4fe0f0fa9d4084",
"index": 0,
"guid": "1d431fc7-8ec1-477b-8a22-d21f2169a474",
"isActive": true,
"age": 29,
"name": "Dixon Downs",
"gender": "male",uino, Louisiana, 4533",
"about": "Ut nostrud consectetur eiusmod est eiusmod sit commodo nulla minim magna. Anim esse fugiat et quis ullamco aliquip enim. Excepteur laboris laboris proident elit aliqua ullamco quis ut reprehenderit et aliquip dolore id labore. Mollit officia quis ullamco mollit. Veniam laborum ex elit ut veniam sunt ullamco ad cupidatat ullamco in. Occaecat in irure excepteur elit pariatur ex ex elit adipisicing occaecat minim.\r\n",
"tags": [
"laborum",
"consectetur",
"occaecat",
"duis",
"dolore",
"sit",
"aute"
],
"friends": [
{
"id": 0,
"name": "Owen Kinney"
},
{
"id": 1,
"name": "Wiggins Marks"
},
{
"id": 2,
"name": "Maura Lara"
}
]
}
]
然后,在IntelliJ IDEA中编写字符串文字:
""
,然后将光标放在两个引号之间,然后粘贴。您会看到:
"[\n" +
" {\n" +
" \"_id\": \"5cc3f7e46a4fe0f0fa9d4084\",\n" +
" \"index\": 0,\n" +
" \"guid\": \"1d431fc7-8ec1-477b-8a22-d21f2169a474\",\n" +
" \"isActive\": true,\n" +
" \"age\": 29,\n" +
" \"name\": \"Dixon Downs\",\n" +
" \"gender\": \"male\",uino, Louisiana, 4533\",\n" +
" \"about\": \"Ut nostrud consectetur eiusmod est eiusmod sit commodo nulla minim magna. Anim esse fugiat et quis ullamco aliquip enim. Excepteur laboris laboris proident elit aliqua ullamco quis ut reprehenderit et aliquip dolore id labore. Mollit officia quis ullamco mollit. Veniam laborum ex elit ut veniam sunt ullamco ad cupidatat ullamco in. Occaecat in irure excepteur elit pariatur ex ex elit adipisicing occaecat minim.\\r\\n\",\n" +
" \"tags\": [\n" +
" \"laborum\",\n" +
" \"consectetur\",\n" +
" \"occaecat\",\n" +
" \"duis\",\n" +
" \"dolore\",\n" +
" \"sit\",\n" +
" \"aute\"\n" +
" ],\n" +
" \"friends\": [\n" +
" {\n" +
" \"id\": 0,\n" +
" \"name\": \"Owen Kinney\"\n" +
" },\n" +
" {\n" +
" \"id\": 1,\n" +
" \"name\": \"Wiggins Marks\"\n" +
" },\n" +
" {\n" +
" \"id\": 2,\n" +
" \"name\": \"Maura Lara\"\n" +
" }\n" +
" ]\n" +
" }\n" +
"]"