[json-lib-user] Square brackets in strings
Brought to you by:
aalmiray
From: Elizabeth K. <ek...@th...> - 2007-02-01 16:04:36
|
<div>Dear Json-lib devs,<br><br>Thank you for your library! It's served us = very well for the past few months.<br><br>Unfortunately my customers have s= tarted putting square brackets just like the example below in the text they're sending us, with the exception that results (from info3= ).<br> <br> public void testThatJsonIsNotConfusedBySquareBracket= s() {<br> HashMap<String, String>= ; map =3D new HashMap<String, String>();<br> = map.put("address", "1 The flats [Upper floor]");<br> &nbs= p; map.put("phoneNumber", "[+44] 582 401923");<br>= map.put("info1", "[Likes coffee]");<b= r> map.put("info2", "[Likes coffee] [L= ikes tea]");<br> map.put("info3", "[Li= kes coffee [but not with sugar]]");<br>  = ; <br> JSONObject json =3D JSONObject.= fromObject(map);<br> }<br><br> Due to the intrigues of mu= ltiple departments all using this data, there's little to no chance of stop= ping them.<br> <br> Can you help?<br><br>The problem seems as though it might be here, in JSONU= tils:<br><br> public static boolean mayBeJSON( String string )<= br> {<br> return string !=3D null= <br> &= ;& ("null".equalsIgnoreCase( string )<br> = ||= (string.startsWith( "[" ) && string.endsWith( "]" )) || (string.st= artsWith( "{" ) && string.endsWith( "}" )));<br> }<br><= br>Is there any chance please of fixing this, eg: by replacing the above wi= th a regular expression that checks the String is truly JSON?<br><br>Many t= hanks,<br>Liz.<br><br><div>--<br>Elizabeth Keogh<br><a href=3D"mailto:= li...@th...">li...@th...</a><br><a href=3D"http://www.liv= ejournal.com/users/sirenian">http://www.livejournal.com/users/sirenian</a><= br></div></div>= |