"{\"AnimalColors\":{\"worm\":\"pink\",\"lamb\":\"black\",\"pig\":\"pink\"},\"plist\":\"Apple\",\"AnimalSounds\":{\"worm\":\"baa\",\"Lisa\":\"Why is the worm talking like a lamb?\",\"lamb\":\"baa\",\"pig\":\"oink\"},\"AnimalSmells\":{\"worm\":\"wormy\",\"lamb\":\"lambish\",\"pig\":\"piggish\"}}",
"{script: 'It is not allowed in HTML to send a close script tag in a string<script>because it confuses browsers</script>so we insert a backslash before the /'}");
assertEquals(
"{\"script\":\"It is not allowed in HTML to send a close script tag in a string<script>because it confuses browsers<\\/script>so we insert a backslash before the /\"}",
jsonobject.toString());
} catch (JSONExceptione)
{
fail(e.getMessage());
}
}
/**
* Tests the toString method using multiple test cases.
*/
publicvoidtestToString_MultipleTestCases()
{
try
{
jsonobject = newJSONObject(
"{ fun => with non-standard forms ; forgiving => This package can be used to parse formats that are similar to but not stricting conforming to JSON; why=To make it easier to migrate existing data to JSON,one = [[1.00]]; uno=[[{1=>1}]];'+':+6e66 ;pluses=+++;empty = '' , 'double':0.666,true: TRUE, false: FALSE, null=NULL;[true] = [[!,@;*]]; string=> o. k. ; \r oct=0666; hex=0x666; dec=666; o=0999; noh=0x0x}");
assertEquals(
"{\n\"noh\": \"0x0x\",\n\"one\": [[1]],\n\"o\": 999,\n\"+\": 6.0E66,\n\"true\": true,\n\"forgiving\": \"This package can be used to parse formats that are similar to but not stricting conforming to JSON\",\n\"fun\": \"with non-standard forms\",\n\"double\": 0.666,\n\"uno\": [[{\"1\": 1}]],\n\"dec\": 666,\n\"oct\": 666,\n\"hex\": \"0x666\",\n\"string\": \"o. k.\",\n\"empty\": \"\",\n\"false\": false,\n\"[true]\": [[\n\"!\",\n\"@\",\n\"*\"\n ]],\n\"pluses\": \"+++\",\n\"why\": \"To make it easier to migrate existing data to JSON\",\n\"null\": null\n}",
jsonobject.toString(1));
assertTrue(jsonobject.getBoolean("true"));
assertFalse(jsonobject.getBoolean("false"));
} catch (JSONExceptione)
{
fail(e.getMessage());
}
}
/**
* Tests the populateMap method using priative class.
"{\"ASCII\":\"American Standard Code for Information Interchange\",\"JSON\":\"JavaScript Object Notation\",\"JAVA\":{\"desc\":\"Just Another Vague Acronym\",\"data\":\"Sweet language\"}}",