[英]How to Deserialize the dictionary and fetch the value of a particular key
How should I get the value of status key?我应该如何获取状态键的值?
string a = "\"[{\\\"Status\\\":\\\"Passed\\\"}]\""
tried with JObject.Parse and JArray.Parse to deserialize it and fetch the value.尝试使用JObject.Parse和JArray.Parse 对其进行反序列化并获取值。 getting error all the time, even if the key is present.
一直出错,即使密钥存在。
PS: this value is coming directly from the DB, where it is stored as a string. PS:这个值直接来自数据库,它存储为一个字符串。
Maybe there is a better solution.也许有更好的解决方案。 But you can
remove the /
character and split by "
但是您可以
remove the /
字符并按split by "
string a = "\"[{\\\"Status\\\":\\\"Passed\\\"}]\"";
var val=a.Replace("\\", "").Split(new string[] { "\"" },
StringSplitOptions.None)[4];
using System.Text.Json;
string a = "\"[{\\\"Status\\\":\\\"Passed\\\"}]\"";
var json = JsonDocument.Parse(a).RootElement.GetString();
var jDoc = JsonDocument.Parse(json);
var dic = jDoc.RootElement[0].Deserialize<Dictionary<string, string>>();
var status = dic["Status"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.