如何从 JSON 类型的字符串创建字典类型的对象

发布于 2024-10-16 06:49:10 字数 403 浏览 5 评论 0原文

我希望从下面的字符串创建一个字典类型的对象,而不使用任何扩展类。我更喜欢编写一个 .net 类来对其进行序列化和反序列化。

string userDetails = "{"FullName":"Manoj Singh","username":"Manoj","Miles":2220,"TierStatus":"Gold","TierMiles":23230,"MilesExpiry":12223,"ExpiryDate":"31 January 2011","PersonID":232323,"AccessToken":"sfs23232s232","ActiveCardNo":"232323223"}";

我的结果中有上面的字符串,现在我想使用 .NET 2.0 将其转换为对象的字典类型。

谢谢。

I am looking to create a dictionary type of object from below string without using any extension class. I would prefer to write a .net class which will do serialize and deserialize it.

string userDetails = "{"FullName":"Manoj Singh","username":"Manoj","Miles":2220,"TierStatus":"Gold","TierMiles":23230,"MilesExpiry":12223,"ExpiryDate":"31 January 2011","PersonID":232323,"AccessToken":"sfs23232s232","ActiveCardNo":"232323223"}";

I have got above string in my results, now I want to convert it into dictionary type of Object using .NET 2.0.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千秋岁 2024-10-23 06:49:10

我等了很多天才得到任何回应,不幸的是没有回应,好吧,我在这个问题的帮助下解决了我的问题你能在.NET中从JSON实例化一个对象实例吗?

感谢所有看到这个问题的人!

I was waiting since many days to have any response on it, unfortunately there were no response, well guys I resolved my problem with the help of this question Can you Instantiate an Object Instance from JSON in .NET?

Thanks to all you who have seen this question!

白况 2024-10-23 06:49:10

试试这个!

Class deserialize<Class>(string jsonStr, Class obj) { /* ... */}

 var jstring = "{fname='Test', lname='test, oth='test'}";
 var p     = deserialize(jstring, new {fname="",lname=""});
 var x     = person.fname; //strongly-typed

try this!!

Class deserialize<Class>(string jsonStr, Class obj) { /* ... */}

 var jstring = "{fname='Test', lname='test, oth='test'}";
 var p     = deserialize(jstring, new {fname="",lname=""});
 var x     = person.fname; //strongly-typed
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文