解析vcard json C# [英] Parse vcard json C#
本文介绍了解析vcard json C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用Json.NET解析vcard RFC 7095:
I want to parse the vcard RFC 7095 using Json.NET :
["vcard",
[
["version", {}, "text", "4.0"],
["fn", {}, "text", "John Doe"],
["gender", {}, "text", "M"],
["categories", {}, "text", "computers", "cameras"],
...
]
]
我尝试使用FormatTypeFormater来执行此操作,但是我无法验证json.
I try to do it using FormatTypeFormater but I cannot validate the json.
推荐答案
您可以使用JavaScriptSerializer
将其解析为object[]
,然后对其进行处理以构建更好的复杂类型:
You can parse it using JavaScriptSerializer
to a object[]
, then work on it to build a better complex type:
var js = new JavaScriptSerializer();
var o = (object[])js.Deserialize(@"[""vcard"",
[
[""version"", {}, ""text"", ""4.0""],
[""fn"", {}, ""text"", ""John Doe""],
[""gender"", {}, ""text"", ""M""],
[""categories"", {}, ""text"", ""computers"", ""cameras""]
]
]", typeof(object[]));
if (o.length > 1 && (o[0] as string) == "vcard")
{
var props = o[1] as object[];
foreach (object[] values in props)
{
switch (values[0] as string)
{
case "version":
...
break;
case "fn":
...
break;
....
}
}
}
您应该对此进行更多验证,但这是一个好的开始.
You should implmenet more validation on this, but this is a good start..
这篇关于解析vcard json C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文