【发布时间】:2017-04-21 08:06:03
【问题描述】:
我尝试使用 Fiddler 读取所有请求和响应,但在某些情况下,我将请求数据作为 JSON 获取,并且我想将该 JSON 解析为键值对。
我试过这样
string requestPost = Utilities.UrlDecode(oSession.GetRequestBodyAsString());
Dictionary<string, string> jsonRequest = new Dictionary<string, string>();
jsonRequest = JsonConvert.DeserializeObject<Dictionary<string, string>>(requestPost);
dataGridViewFiddler.DataSource = jsonRequest;
但这对我不起作用。
这是我的 Json 格式
{"entries":[{"http_response_code":200,"network_changed":false,"protocol":"QUIC","request_age_ms":112425,"request_elapsed_ms":27,"sample_rate":0.05,"server_ip":"216.58.197.78:443","status":"ok","url":"https://www.google-analytics.com/","was_proxied":false}],"reporter":"chrome"}
现在如果我使用动态来解析这个 json 它的工作但是
【问题讨论】:
-
请告诉我们
requestPost长什么样子? -
@Luke requestpost 可以是任何 json..
-
如果您的 JSON 真的可以是任何东西,那么“How do I use JSON.NET to deserialize into nested/recursive Dictionary and List?”可能会对您有所帮助。但请注意,并非每个 JSON 都可以解析为键值对。如果你从 JSON 中的一个数组开始,那么你在解析它时会得到一个列表。