Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit da103ad

Browse files
author
code4wt
committed
新增JSON美化测试
1 parent f8cb502 commit da103ad

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

‎src/test/java/com/titizz/jsonparser/JSONParserTest.java‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,26 @@ public void fromJSON1() throws Exception {
7878
assertEquals(null, d.get(8));
7979
}
8080

81+
@Test
82+
public void fromJSON2() throws Exception {
83+
String json = "[[1,2,3,\"\u4e2d\"]]";
84+
JSONParser jsonParser = new JSONParser();
85+
JsonArray jsonArray = (JsonArray) jsonParser.fromJSON(json);
86+
System.out.println(jsonArray);
87+
}
88+
89+
@Test
90+
public void beautifyJSON() throws Exception {
91+
String json = "{\"name\": \"狄仁杰\", \"type\": \"射手\", \"ability\":[\"六令追凶\",\"逃脱\",\"王朝密令\"],\"history\":{\"DOB\":630,\"DOD\":700,\"position\":\"宰相\",\"dynasty\":\"唐朝\"}}";
92+
System.out.println("原 JSON 字符串:");
93+
System.out.println(json);
94+
System.out.println("\n");
95+
System.out.println("美化后的 JSON 字符串:");
96+
JSONParser jsonParser = new JSONParser();
97+
JsonObject drj = (JsonObject) jsonParser.fromJSON(json);
98+
System.out.println(drj);
99+
}
100+
81101
private String getJSON() throws IOException {
82102
String url = "http://music.163.com/weapi/v3/playlist/detail";
83103
List<BasicNameValuePair> params = new ArrayList<>();

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /