【发布时间】:2014-04-22 01:14:22
【问题描述】:
我收到推文并使用 org.json.simple api 将字符串转换为对象。
JSONParser jsonParser = new JSONParser();
Object json = jsonParser.parse(in);
我想使用 couchdb4j api 将 obj 插入 couchdb
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);
错误是:
org.json.simple.JSONObject cannot be cast to net.sf.json.JSONObject
如何解决这个问题或者任何人都可以给出一个解决方案,将一个json格式的字符串或对象插入到couchdb中
【问题讨论】:
-
检查你的导入,确保你使用库正确解析json,也就是说如果你使用json.simple,那么最好不要使用
net.sf.json.JSONObjectobject。