@@ -309,22 +309,18 @@ public void testEncode() throws Exception{
309
309
assertEquals ("[\" abc\\ u0010a\\ /\" ,123,222.123,true]" ,array1 .toString ());
310
310
311
311
JSONObject obj1 =new JSONObject ();
312
- obj1 .put ("name" ,"fang" );
313
- obj1 .put ("age" ,new Integer (27 ));
314
- obj1 .put ("is_developer" ,new Boolean (true ));
315
- obj1 .put ("weight" ,new Double (60.21 ));
316
312
obj1 .put ("array1" ,array1 );
317
313
System .out .println ("======obj1 with array1===========" );
318
314
System .out .println (obj1 );
319
315
System .out .println ();
320
- assertEquals ("{\" array1\" :[\" abc\\ u0010a\\ /\" ,123,222.123,true], \" weight \" :60.21, \" age \" :27, \" name \" : \" fang \" , \" is_developer \" :true }" ,obj1 .toString ());
316
+ assertEquals ("{\" array1\" :[\" abc\\ u0010a\\ /\" ,123,222.123,true]}" ,obj1 .toString ());
321
317
322
318
obj1 .remove ("array1" );
323
319
array1 .add (obj1 );
324
320
System .out .println ("======array1 with obj1========" );
325
321
System .out .println (array1 );
326
322
System .out .println ();
327
- assertEquals ("[\" abc\\ u0010a\\ /\" ,123,222.123,true,{\" weight \" :60.21, \" age \" :27, \" name \" : \" fang \" , \" is_developer \" :true }]" ,array1 .toString ());
323
+ assertEquals ("[\" abc\\ u0010a\\ /\" ,123,222.123,true,{}]" ,array1 .toString ());
328
324
329
325
List list = new ArrayList ();
330
326
list .add ("abc\u0010 a/" );
@@ -336,20 +332,16 @@ public void testEncode() throws Exception{
336
332
System .out .println (JSONArray .toJSONString (list ));
337
333
System .out .println ();
338
334
assertEquals ("[\" abc\\ u0010a\\ /\" ,123,222.123,true,null]" ,JSONArray .toJSONString (list ));
339
-
335
+
340
336
Map map = new HashMap ();
341
- map .put ("name" ,"fang" );
342
- map .put ("age" ,new Integer (27 ));
343
- map .put ("is_developer" ,new Boolean (true ));
344
- map .put ("weight" ,new Double (60.21 ));
345
337
map .put ("array1" ,list );
346
338
System .out .println ("======map with list===========" );
347
339
System .out .println (map );
348
340
System .out .println ();
349
- assertEquals ("{\" array1\" :[\" abc\\ u0010a\\ /\" ,123,222.123,true,null], \" weight \" :60.21, \" age \" :27, \" name \" : \" fang \" , \" is_developer \" :true }" ,JSONObject .toJSONString (map ));
341
+ assertEquals ("{\" array1\" :[\" abc\\ u0010a\\ /\" ,123,222.123,true,null]}" ,JSONObject .toJSONString (map ));
350
342
351
343
Map m1 = new LinkedHashMap ();
352
- Map m2 = new HashMap ();
344
+ Map m2 = new LinkedHashMap ();
353
345
List l1 = new LinkedList ();
354
346
355
347
m1 .put ("k11" ,"v11" );
@@ -362,13 +354,13 @@ public void testEncode() throws Exception{
362
354
l1 .add (m2 );
363
355
String jsonString = JSONValue .toJSONString (l1 );
364
356
System .out .println (jsonString );
365
- assertEquals ("[{\" k11\" :\" v11\" ,\" k12\" :\" v12\" ,\" k13\" :\" v13\" },{\" k22 \" :\" v22 \" ,\" k21 \" :\" v21 \" ,\" k23\" :\" v23\" }]" , jsonString );
357
+ assertEquals ("[{\" k11\" :\" v11\" ,\" k12\" :\" v12\" ,\" k13\" :\" v13\" },{\" k21 \" :\" v21 \" ,\" k22 \" :\" v22 \" ,\" k23\" :\" v23\" }]" , jsonString );
366
358
367
359
StringWriter out = new StringWriter ();
368
360
JSONValue .writeJSONString (l1 , out );
369
361
jsonString = out .toString ();
370
362
System .out .println (jsonString );
371
- assertEquals ("[{\" k11\" :\" v11\" ,\" k12\" :\" v12\" ,\" k13\" :\" v13\" },{\" k22 \" :\" v22 \" ,\" k21 \" :\" v21 \" ,\" k23\" :\" v23\" }]" , jsonString );
363
+ assertEquals ("[{\" k11\" :\" v11\" ,\" k12\" :\" v12\" ,\" k13\" :\" v13\" },{\" k21 \" :\" v21 \" ,\" k22 \" :\" v22 \" ,\" k23\" :\" v23\" }]" , jsonString );
372
364
373
365
List l2 = new LinkedList ();
374
366
Map m3 = new LinkedHashMap ();
@@ -386,6 +378,6 @@ public void testEncode() throws Exception{
386
378
JSONValue .writeJSONString (l1 , out );
387
379
jsonString = out .toString ();
388
380
System .out .println (jsonString );
389
- assertEquals ("[{\" k11\" :\" v11\" ,\" k12\" :\" v12\" ,\" k13\" :\" v13\" ,\" k14\" :{\" k31\" :\" v3\" ,\" k32\" :123.45,\" k33\" :false,\" k34\" :null,\" k35\" :[\" vvv\" ,\" 1.23456789123456789\" ,true,null]}},{\" k22 \" :\" v22 \" ,\" k21 \" :\" v21 \" ,\" k23\" :\" v23\" }]" ,jsonString );
381
+ assertEquals ("[{\" k11\" :\" v11\" ,\" k12\" :\" v12\" ,\" k13\" :\" v13\" ,\" k14\" :{\" k31\" :\" v3\" ,\" k32\" :123.45,\" k33\" :false,\" k34\" :null,\" k35\" :[\" vvv\" ,\" 1.23456789123456789\" ,true,null]}},{\" k21 \" :\" v21 \" ,\" k22 \" :\" v22 \" ,\" k23\" :\" v23\" }]" ,jsonString );
390
382
}
391
383
}
0 commit comments