RavenDB,存储 Json 对象 (c#) [英] RavenDB, storing Json Object (c#)

查看:53
本文介绍了RavenDB,存储 Json 对象 (c#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码将字符串变量解析为 Json 对象:

I am parsing a string variable into a Json Object with the following code:

string[] rInfo = r.Info.ToString().Split('|'); 
dynamic JSON_Obj = JObject.Parse(rInfo[0]);

它在代码中看起来很好,这意味着如果我在运行时检查对象,它具有正确的内容.但是,在我将它存储在 RavenDB 之后,它看起来像这样:

And it is looking fine in the Code, meaning if i check the object at runtime it has the right contents. However, after i store it in RavenDB it looks like this:

{"street": {
    "$type": "Newtonsoft.Json.Linq.JValue, Newtonsoft.Json",
    "$values": []
},
"country": {
    "$type": "Newtonsoft.Json.Linq.JValue, Newtonsoft.Json",
    "$values": []
}}

例如在国家/地区应该类似于ES"或GB".

For example in country should be something like "ES" or "GB".

我将 JSON 对象存储为文档的一部分,如下所示:

I am storing the JSON Object as part of a document like this:

                PATCHED_Doc Doc = new PATCHED_Doc()
                {
                    Info = JSON_Obj, 
                    Value = "test",
                    Id = r.Id,
                    Date = r.Date,
                };

                session.Store(Doc);
                session.SaveChanges();

预先感谢您的帮助.

推荐答案

fahadash 是对的.我必须创建一个类来映射属性.

fahadash was right. I had to crate a class to map the attributes.

var JSON_Obj = Newtonsoft.Json.JsonConvert.DeserializeObject<Infolist>(strJSON);

Infolist 是:

public class Infolist
{
    public string street { get; set; }
    public string coutnry { get; set; }
    ...
}

像这样它正在工作......

Like this it is working...

这篇关于RavenDB,存储 Json 对象 (c#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆