JSON values got reversed while modifying response in fiddler

匿名 (未验证) 提交于 2019-12-03 02:41:02

问题:

static function OnBeforeResponse(oSession: Session) {         if (m_Hide304s && oSession.responseCode == 304) {             oSession["ui-hide"] = "true";         }         if (oSession.host == "localhost:8000") {             var sbody = oSession.GetResponseBodyAsString();             var oJSON1:Fiddler.WebFormats.JSON.JSONParseResult=Fiddler.WebFormats.JSON.JsonDecode(sbody);             //some junk modification            var value = oJSON1.JSONObject["n4"];            value + =1;             oJSON1.JSONObject["n4"] = value;              // Convert back to a byte array             var modBytes = Fiddler.WebFormats.JSON.JsonEncode(oJSON1.JSONObject);              // Convert json to bytes, storing the bytes in request body             var mod = System.Text.Encoding.UTF8.GetBytes(modBytes);             oSession.responseBody = mod;          }     } 

The server has sent the right JSON response:

{"n4":"9pjjvezwRVUIvycpsXco4g==","eB":[92,684,"dLzPnLRYquJ7b7b"]} 

which I captured in OnBeforeResponse function to modify and send it to the client.

In OnBeforeResponse function:

var sbody = oSession.GetResponseBodyAsString(); 

gives me the right JSON response as above, but when I convert JSON back to byte array using

var modBytes = Fiddler.WebFormats.JSON.JsonEncode(oJSON1.JSONObject); 

at this point my JSON response got reversed to

{"eB":[92,684,"dLzPnLRYquJ7b7b"], "n4":"9pjjvezwRVUIvycpsXco4g==1"} 

I am not able to figure out what I am doing wrong. Please help me out. Completely new to Fiddler and JSON.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!