Basically, I'm trying to do this:
@Test
public void testCreateFromString() {
BasicDBObject obj = new BasicDBObject("{'username': 'xirby'}");
assertNotNull(obj.get("username"));
}
@Test
public void testCreateQueryFromString() {
BasicDBObject query = new BasicDBObject("{'$inc': {number: 1}}");
assertNotNull(query.get("$inc"));
}
Both test fails, with error:
Unexpected character (') at position 2.
at org.json.simple.parser.Yylex.yylex(Unknown Source)
BasicDBObject.java: (w/c is a HashMap)
public BasicDBObject(String doc){
try {
JSONParser parser=new JSONParser();
Object obj = parser.parse(doc);
if (obj != null){
if (obj instanceof JSONObject){
putAll((Map<String,Object>) obj);
}
} else {
throw new RuntimeException("Cannot parse document: " + doc);
}
} catch (Exception e) {
e.printStackTrace();
}
}
Its most likely that the JSON String would be like this on code to eliminate the need to \
escape character:
"{'username' : 'xirby'}"
So are there any JSON parser that could parse this?
Or
Perhaps, a library that can turn this String into a valid JSON String.