在CSharp中反序列化来自OrientDB的JSON响应

本文关键字:OrientDB JSON 响应 CSharp 反序列化 | 更新日期: 2023-09-27 18:15:11

我开始测试OrientDB。我从演示数据库得到以下JSON响应:

{
    "schema":{
        "name":"OUser",
        "properties":{
            "roles":{
                "name":"roles",
                "linkedClass":"ORole",
                "type":"LINKSET",
                "mandatory":false,
                "notNull":true,
                "min":null,
                "max":null
            },
            "name":{
                "name":"name",
                "type":"STRING",
                "mandatory":true,
                "notNull":false,
                "min":null,
                "max":null
            },
            "password":{
                "name":"password",
                "type":"STRING",
                "mandatory":true,
                "notNull":false,
                "min":null,
                "max":null
            }
        }
    },
    "result":[
        {
            "@type":"d",
            "@rid":"#4:0",
            "@version":0,
            "@class":"OUser",
            "name":"admin",
            "password":"{SHA-256}8C6976E5B5410415BDE908BD4DEE15DFB167A9C873FC4BB8A81F6F2AB448A918",
            "status":"ACTIVE",
            "roles":[
                "#3:0"
            ]
        },
        {
            "@type":"d",
            "@rid":"#4:1",
            "@version":0,
            "@class":"OUser",
            "name":"reader",
            "password":"{SHA-256}3D0941964AA3EBDCB00CCEF58B1BB399F9F898465E9886D5AEC7F31090A0FB30",
            "status":"ACTIVE",
            "roles":[
                "#3:1"
            ]
        },
        {
            "@type":"d",
            "@rid":"#4:2",
            "@version":0,
            "@class":"OUser",
            "name":"writer",
            "password":"{SHA-256}B93006774CBDD4B299389A03AC3D88C3A76B460D538795BC12718011A909FBA5",
            "status":"ACTIVE",
            "roles":[
                "#3:2"
            ]
        }
    ]
}

你如何从中得到一个用户对象列表?使用JSON。Net, JavaScriptSerializer之类的?

在CSharp中反序列化来自OrientDB的JSON响应

c#有很多json解析器:http://www.json.org/。看起来fastJSON应该是相当快的

登录后对用户类执行查询:

select from ouser

通过HTTP协议将是针对此地址的GET请求:

http://localhost: 2480/查询/演示/sql/从% 20配偶选择% 20

{  
  "result": [{
    "@type": "d", "@rid": "#4:0", "@version": 0, "@class": "OUser", 
    "name": "admin", 
    "password": "{SHA-256}8C6976E5B5410415BDE908BD4DEE15DFB167A9C873FC4BB8A81F6F2AB448A918", 
    "status": "ACTIVE", 
    "roles": ["#3:0"]
  }, {
    "@type": "d", "@rid": "#4:1", "@version": 2, "@class": "OUser", 
    "name": "reader", 
    "password": "{SHA-256}3D0941964AA3EBDCB00CCEF58B1BB399F9F898465E9886D5AEC7F31090A0FB30", 
    "status": "ACTIVE", 
    "roles": ["#3:1"]
  }, {
    "@type": "d", "@rid": "#4:2", "@version": 0, "@class": "OUser", 
    "name": "writer", 
    "password": "{SHA-256}B93006774CBDD4B299389A03AC3D88C3A76B460D538795BC12718011A909FBA5", 
    "status": "ACTIVE", 
    "roles": ["#3:2"]
  }

)}

这看起来像是一个使用json反序列化的简单结构。净