如果我想在没有名称的情况下反序列化一个值怎么办? [英] what if text which I wants to deserialize one value without name?
本文介绍了如果我想在没有名称的情况下反序列化一个值怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我想对不带名称的一个值进行反序列化的文本怎么办?
what if text which I wants to deserialize one value without name?
推荐答案
好,现在我明白了.您可以在设置文件中创建空白值,只需将它们保留为空白即可,但是必须将VALUE保留为空白,您不能具有变量或具有值的设置,但是没有名称. string.Empty表示一个空字符串,您无需在代码中创建某些内容即可将空字符串作为属性使用.为什么需要这个?
我认为您可能需要发布一些代码并解释一下为什么要得到想要的东西(如果我尚未正确回答您的话).
OK, now I see what you want. You can create blank values in the settings file, just leave them blank, but you have to leave the VALUE blank, you can''t have a variable or a setting that has a value, but no name. string.Empty denotes an empty string, you don''t need to create something in code to have an empty string available to you as a property. Why do you need this ?
I think you need to probably post some code and explain WHY you want what you want, if I have not answered you correctly already.
这取决于解析器.
我已使用Newtonsoft解析器对Json对象进行序列化/反序列化,
检查下面的代码,
It depends on the parser.
I have used Newtonsoft parser to serialize/deserialize Json object,
Check the code below,
internal struct namestruct
{
public string fname { get; set; }
public string lname { get; set; }
}
protected void Page_Load(object sender, EventArgs e)
{
string json =
@"{
""name"":{
""fname"":""Sandip"",
""lbname"":""Nascar""
},
""name_0"":{
""fname"":""Jon"",
""lbname"":""Doe""
},
""name_1"":{
""fname"":""Michael"",
""lbname"":""Ferrara""
},
"""":{
""fname"":""No Name"",
},
}";
var values = JsonConvert.DeserializeObject<dictionary><string,>>(json);
string valuefname_1 = values["name_0"].fname;
string valuenoname_1 = values[""].fname;//see. I have accessed it with name having Empty.String
</dictionary>
希望这会有所帮助.
欢呼
Hope this helps.
cheers
这篇关于如果我想在没有名称的情况下反序列化一个值怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文