I get tweets and use org.json.simple api to convert a string to a object.
JSONParser jsonParser = new JSONParser();
Object json = jsonParser.parse(in);
and I would like to insert the obj into couchdb using couchdb4j api
Session myDbSession = new Session("localhost",5984)
Database myCouchDb = myDbSession.getDatabase("db-name");
Document newdoc = new Document();
Document newdoc = new Document(JSONObject json);
myCouchDb.saveDocument(newdoc);
The error is:
org.json.simple.JSONObject cannot be cast to net.sf.json.JSONObject
how to solve this problem or anyone can give a solution to insert a json format string or object into couchdb
As the error said, couchdb may use net.sf.json.JSONObject.
I've found an API in net.sf.json.JSONObject to convert a string to JSON object:
public static JSONObject fromObject( Object object ) {
return fromObject( object, new JsonConfig() );
}
It's OK with String cause
else if( object instanceof String ){
return _fromString( (String) object, jsonConfig );
}
This may be help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With