怎样将DBObject类型转换为JSON
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了怎样将DBObject类型转换为JSON相关的知识,希望对你有一定的参考价值。
不是DBObject转换成JSONObject,是JSON
DBObject dbo;
JSON json= dbo
一句话即可:
DBObject userDb = (DBObject) com.mongodb.util.JSON.parse(user
.toString());
示例如下:
import com.mongodb.DBObject;
import net.sf.json.JSONObject;
//JSONObect 转化成 DBJONObject
public class JSONObjectTotestDBObject
public static void main(String[] rags)
// 一个JSONObject类
JSONObject user = new JSONObject();
user.put("name", "xiaoA");
user.put("age", 12);
// 打印该类
System.out.println(user);
System.out.println("------------------------");
// 转化
DBObject userDb = (DBObject) com.mongodb.util.JSON.parse(user
.toString());
System.out.print(userDb);
参考技术A DBObject obj=new DBObject();
JSONObject jsonObj= JSONObject.fromObject(obj);
String json=jsonObj.toString();
webservice怎样接收json类型的参数
参考技术A 在接口中定义String类型的参数,传递的时候将json转化为String进行传递,接收到后再将String转化为json对象。本回答被提问者采纳 参考技术B 可以用map将你的json封装json,然后将map和json互相转就可以了 参考技术C 在webservice中的参赛类型可以为string类型,传进去之后用.NET自带的JSS或者LetJson转换为相应对象就可以了。以上是关于怎样将DBObject类型转换为JSON的主要内容,如果未能解决你的问题,请参考以下文章