怎样将DBObject类型转换为JSON

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了怎样将DBObject类型转换为JSON相关的知识,希望对你有一定的参考价值。

不是DBObject转换成JSONObject,是JSON
DBObject dbo;
JSON json= dbo

JSONObject 转化成 DBObject 的思路是把JSONObject 转化成String ,再转换成DBObject 或者BaicDBObject类型
一句话即可:
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的主要内容,如果未能解决你的问题,请参考以下文章

JSONObjec的作用详解——Web网络系列学习笔记

bean和DBObject相互转换的方法

把实体bean对象转换成DBObject工具类

(在线等)js怎样将字符串类型转换为int类型

java怎样将集合类型转换为数组类型

java中int怎样转换成char