我嘗試使用Fiddler讀取所有請求和響應,但在某些情況下,我將請求數據作爲JSON獲取,並且我想將該JSON解析爲鍵值對。將任何Json解析爲Key值對
我已經試過這樣
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
@Luke requestpost可能是任何json .. –
如果你的JSON真的可以是任何東西,那麼「[我如何使用JSON.NET反序列化爲嵌套/遞歸Dictionary和List?](http://stackoverflow.com/q/5546142/10263)「可能對你有幫助。但請注意,並非每個JSON都可以被解析爲鍵值對。如果你從一個JSON數組開始,那麼當你解析它時你會得到一個列表。 –