简体   繁体   English

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

[英]Deserialize a JSON Response from OrientDB in CSharp

I started testing OrientDB. 我开始测试OrientDB。 I get the following JSON Response from the Demo Database: 我从演示数据库中获得以下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"
            ]
        }
    ]
}

How can you get a List of OUser Objects out of that? 如何从中获取OUser对象列表? Using JSON.Net, JavaScriptSerializer or whatever? 使用JSON.Net,JavaScriptSerializer还是其他什么?

There are a number of json parsers for c# at: http://www.json.org/ . 有许多针对c#的json解析器: http//www.json.org/ It seems like fastJSON should be pretty quick. 似乎fastJSON应该很快。

Once logged in execute a query against OUser class: 登录后,对OUser类执行查询:

select from ouser

Via HTTP protocol would be a GET request against this address: 通过HTTP协议将是针对此地址的GET请求:

http://localhost:2480/query/demo/sql/select%20from%20ouser HTTP://本地主机:2480 /查询/演示/ SQL /选%20from%20ouser

{  
  "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.NET进行反序列化的简单结构

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM