View the ** most convenient ** method of Json output)

Source: Internet
Author: User
Tags jsonviewer fiddler2

No extra effort required to view Json output at any time

"No extra effort required" means that when you need to view the Json output, you only need to turn your eyes around (you may need to at least two more mouse clicks, I'm afraid) you can quickly find the desired result.
There are many ways to view Json output. The solution we can find is "Fiddler2 + JsonViewer plug-in + custom Fiddler2 filter condition ". To view the Json output, you only need to run Fiddler first and then operate the Web page normally in the browser. Then, you can see the intercepted Json output in Fiddler, as shown in.

Install the Fiddler2 + JsonViewer plug-in

Fiddler2 is an old Web debugging tool. After the download and installation, click Start | program | Fiddler2 or choose tools | Fiddler2 from the IE menu to run the tool, it automatically registers itself as the proxy server of IE to intercept any requests/responses that pass through IE. When it is disabled, it will automatically cancel the proxy server configuration (You have to add the proxy server configuration yourself when using Fiddler1 that year, which is very troublesome to say ).
JsonViewer is a small tool for viewing Json objects. After decompression, You can see three subdirectories:
-JsonView: runs independently.
-Visualizer: VS2005 plug-in.
-Fiddler: The Fiddler2 plug-in.
We will install the Fiddler2 plug-in of JsonViewer. By copying all the files in the Fiddler directory to the "install directory \ Inspectors \" of fiddler2 \". Then modify "install directory \ fiddler.exe. config of Fiddler2", as shown in. The bold part is the configuration information that needs to be added.

Copy codeThe Code is as follows: <configuration>
<Runtime>
<GeneratePublisherEvidence enabled = "false"/>
<AssemblyBinding xmlns = "urn: schemas-microsoft-com: asm. v1">
<Probing privatePath = "Inspectors"/>
</AssemblyBinding>
</Runtime>
</Configuration>

Note that IE7 and. NET Framework are hardcoded as long as they are requests to localhost, they do not pass through the proxy server. Therefore, requests such as "http: // localhost: 8000/Default. aspx" will not be intercepted by fiddler2. Solution: 1) Replace "localhost" with "localhost. ", such as" http: // localhost.: 8000/Default. aspx "; 2) Replace" localhost "with the IP address of the cost server, for example," http: // 172.16.75.78: 8000/Default. aspx ".
Now, let's run Fiddler2 and click the page to view a large number of requests/responses in the "Web Sessions" list on the left side of the Fiddler2 form. Click the one that returns Json, and then click the "Inspectors" and "Json" Tab pages on the right. However, by default, Fiddler2 will display all requests/responses that pass through IE. As a result, there are too many things in the "Web Sessions" list, can I filter out all the items irrelevant to Json? This is not difficult. You only need to add a few lines of code in "mrmrules" of Fiddler2.
Custom filter conditions
Click "Rules | Customize Rules..." in the menu of Fiddler2. The code file that can add custom Rules is automatically opened in notepad.
Add the following code in line 1 to add a menu item "show Json only" in the Rules menu of Fiddler2:
// Jcl20091121
Public static RulesOption ("show only & Json ")
Var m_ShowJsonOnly: boolean = false;
Add the following code to the OnBeforeResponse event, which means that if the "Rules | display only Json" menu item is selected, all Content-types will be filtered out! = "Application/json; charset = UTF-8.Copy codeThe Code is as follows: // jcl: 2009-11-21
If (m_ShowJsonOnly ){
// MessageBox. Show (oSession. oResponse. headers. Item ("Content-Type"). ToString ());
If (! OSession. oResponse. headers. ExistsAndContains ("Content-Type", "application/json; charset = UTF-8 ")){
OSession ["ui-hide"] = "hide"; // String value not important
}
}

All source code here:
Custom RulesCopy codeThe Code is as follows: import System;
Import System. Windows. Forms;
Import Fiddler;
// Globalization note:
// Be sure to save this file with UTF-8 Encoding if using any non-ASCII characters
// In strings, etc.
//
// JScript Reference
// Http://www.fiddler2.com/redir? Id = msdnjsnet
//
// FiddlerScript Reference
// Http://www.fiddler2.com/redir? Id = fiddlerscriptcookbook
//
// FiddlerScript Editor:
// Http://www.fiddler2.com/redir? Id = fiddlerscripteditor
Class Handlers
{
// The following snippet demonstrates a custom-bound column for the web sessions list.
// See http://www.fiddler2.com/fiddler/help/configurecolumns.asp for more info
// Public static BindUIColumn ("Method", 60)
// Function FillMethodColumn (OS: Session ){
// If (OS. oRequest! = Null) & (OS. oRequest. headers! = Null ))
// Return OS. oRequest. headers. HTTPMethod; else return String. Empty;
//}
Public static RulesOption ("Hide 304 s ")
Var m_Hide304s: boolean = false;
// Cause Fiddler to override the Accept-Language header with one of the defined values
Public static RulesOption ("Request & Japanese Content ")
Var m_Japanese: boolean = false;
// Cause Fiddler to override the User-Agent header with one of the defined values
RulesString ("& User-Agents", true)
RulesStringValue (0, "Netscape & 3", "Mozilla/3.0 (Win95; I )")
RulesStringValue (1, "& IEMobile", "Mozilla/4.0 (compatible; MSIE 6.0; Windows CE; IEMobile 6.12 )")
RulesStringValue (2, "& Safari (XP)", "Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US) AppleWebKit/531.9 (KHTML, like Gecko) version/4.0.3 Safari/531.9.1 ")
RulesStringValue (3, "IE & 6 (XPSP2)", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1 )")
RulesStringValue (4, "IE & 7 (Vista)", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Server Load balancer )")
RulesStringValue (5, "IE & 8 (Win2k3 x64)", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; WOW64; Trident/4.0 )")
RulesStringValue (6, "IE 8 (Win7)", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0 )")
RulesStringValue (7, "IE 8 (IE7 CompatMode)", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0 )")
RulesStringValue (8, "& Opera 10", "Opera/9.80 (Windows NT 5.2; U; en) Presto/2.2.15 Version/10.00 ")
RulesStringValue (9, "& Firefox 2", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: 1.8.1.10) Gecko/20071115 Firefox/2.0.0.10 ")
RulesStringValue (10, "& Firefox 3.5", "Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv: 1.9.1.3) Gecko/20090824 Firefox/3.5.3 ")
RulesStringValue (10, "& Firefox (Mac)", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv: 1.9.1.3) gecko/20090824 Firefox/3.5.3 ")
RulesStringValue (12, "Chrome", "Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US) AppleWebKit/532.0 (KHTML, like Gecko) chrome/3.0.195.24 Safari/532.0 ")
RulesStringValue (13, "& Custom", "% CUSTOM % ")
Public static var sUA: String = null;
// Cause Fiddler to delay HTTP traffic to simulate typical 56 k modem conditions
Public static RulesOption ("Simulate & Modem speeds", "Per & formance ")
Var m_SimulateModem: boolean = false;
// Removes HTTP-caching related headers and specifies "no-cache" on requests and responses
Public static RulesOption ("& Disable Caching", "Per & formance ")
Var m_DisableCaching: boolean = false;
// Show the duration between the start of Request. Send and Response. Completed in Milliseconds
Public static RulesOption ("& Show Time-to-Last-Byte", "Per & formance ")
Var m_ShowTTLB: boolean = false;
// Show the time of response completion
Public static RulesOption ("Show Response & Timestamp", "Per & formance ")
Var m_ShowTimestamp: boolean = false;
// Create a new option on the Rules menu. Set the default value for the option.
Public static RulesOption ("& UNTITLED ")
Var m_bUNTITLED: boolean = false;
// Create a new item on the Tools menu.
Public static ToolsAction ("& UNTITLED ")
Function DoUNTITLED (oSessions: Fiddler. Session []) {
// Write your code here
}
// Jcl20091121
Public static RulesOption ("show only & Json ")
Var m_ShowJsonOnly: boolean = false;
// Force a manual reload of the script file. Resets all
// RulesOption variables to their ults.
Public static ToolsAction ("Reset Script ")
Function DoManualReload (){
FiddlerObject. ReloadScript ();
}
Public static ContextAction ("Decode Selected Sessions ")
Function DoRemoveEncoding (oSessions: Session []) {
For (var x = 0; x <oSessions. Length; x ++ ){
OSessions [x]. utilDecodeRequest ();
OSessions [x]. utilDecodeResponse ();
}
}
Static function OnBoot (){
// MessageBox. Show ("Fiddler has finished booting ");
// System. Diagnostics. Process. Start ("ipolice.exe ");
// FiddlerObject. UI. ActivateRequestInspector ("HEADERS ");
// FiddlerObject. UI. ActivateResponseInspector ("HEADERS ");
}
Static function OnShutdown (){
// MessageBox. Show ("Fiddler has shutdown ");
}
Static function OnAttach (){
// MessageBox. Show ("Fiddler is now the system proxy ");
// System. Diagnostics. Process. Start ("proxycmd.exe", "-u"); // configure y WinHTTP of proxy change
}
Static function OnDetach (){
// MessageBox. Show ("Fiddler is no longer the system proxy ");
// System. Diagnostics. Process. Start ("proxycmd.exe", "-u"); // configure y WinHTTP of proxy change
}
Static function OnBeforeRequest (oSession: Session)
{
// Sample Rule: Color ASPX requests in RED
// If (oSession. uriContains (". aspx") {oSession ["ui-color"] = "red ";}
// Sample Rule: Flag POSTs to fiddler2.com in italics
// If (oSession. HostnameIs ("www.fiddler2.com") & oSession. HTTPMethodIs ("POST") {oSession ["ui-italic"] = "yup ";}
// Sample Rule: Break requests for URLs containing "/sandbox /"
// If (oSession. uriContains ("/sandbox /")){
// OSession. oFlags ["x-breakrequest"] = "yup"; // Existence of the x-breakrequest flag creates a breakpoint; the "yup" value is unimportant.
//}
If (null! = Gs_ReplaceToken) & (oSession. url. indexOf (gs_ReplaceToken)>-1) {// Case sensitive
OSession. url = oSession. url. Replace (gs_ReplaceToken, gs_ReplaceTokenWith );
}
If (null! = Gs_OverridenHost) & (oSession. host. toLowerCase () = gs_OverridenHost )){
OSession ["x-overridehost"] = gs_OverrideHostWith;
}
If (null! = BpRequestURI) & oSession. uriContains (bpRequestURI )){
OSession ["x-breakrequest"] = "uri ";
}
If (null! = BpMethod) & (oSession. HTTPMethodIs (bpMethod ))){
OSession ["x-breakrequest"] = "method ";
}
If (null! = UiBoldURI) & oSession. uriContains (uiBoldURI )){
OSession ["ui-bold"] = "QuickExec ";
}
If (m_SimulateModem ){
// Delay sends by 300 ms per KB uploaded.
OSession ["request-trickle-delay"] = "300 ";
}
If (m_DisableCaching ){
OSession. oRequest. headers. Remove ("If-None-Match ");
OSession. oRequest. headers. Remove ("If-Modified-Since ");
OSession. oRequest ["Pragma"] = "no-cache ";
}
// User-Agent Overrides
If (null! = SUA ){
OSession. oRequest ["User-Agent"] = sUA;
}
If (m_Japanese ){
OSession. oRequest ["Accept-Language"] = "ja ";
}
}
Static function OnBeforeResponse (oSession: Session)
{
If (m_SimulateModem ){
// Delay receives by 150 ms per KB downloaded.
OSession ["response-trickle-delay"] = "150 ";
}
If (m_DisableCaching ){
OSession. oResponse. headers. Remove ("Expires ");
OSession. oResponse ["Cache-Control"] = "no-cache ";
}
If (m_ShowTimestamp ){
OSession ["ui-customcolumn"] = DateTime. Now. ToString ("H: mm: ss. ffff") + "" + oSession ["ui-customcolumn"];
}
If (m_ShowTTLB ){
OSession ["ui-customcolumn"] = oSession. oResponse. iTTLB + "ms" + oSession ["ui-customcolumn"];
}
If (m_Hide304s & oSession. responseCode = 304 ){
OSession ["ui-hide"] = "true ";
}
If (bpStatus> 0) & (oSession. responseCode = bpStatus )){
OSession ["x-breakresponse"] = "status ";
}
If (null! = BpResponseURI) & oSession. uriContains (bpResponseURI )){
OSession ["x-breakresponse"] = "uri ";
}
// Jcl: 2009-11-21
If (m_ShowJsonOnly ){
// MessageBox. Show (oSession. oResponse. headers. Item ("Content-Type"). ToString ());
If (! OSession. oResponse. headers. ExistsAndContains ("Content-Type", "application/json; charset = UTF-8 ")){
OSession ["ui-hide"] = "hide"; // String value not important
}
}
// Uncomment to reduce incidence of "unexpected socket closure" exceptions in. NET code.
// Note that you really shocould also fix your. NET code to gracefully handle unexpected connection closure.
//
// If (! (OSession. responseCode = 401) & oSession. oResponse ["WWW-Authenticate"]. Length> 9) |
// (OSession. responseCode = 407) & oSession. oResponse ["Proxy-Authenticate"]. Length> 9 ))){
// OSession. oResponse ["Connection"] = "close ";
//}
}
Static function Main ()
{
Var today: Date = new Date ();
FiddlerObject. StatusText = "CustomRules. js was loaded at:" + today;
// Uncomment to add a "Server" column containing the response "Server" header, if present
// FiddlerObject. UI. lvSessions. AddBoundColumn ("Server", 50, "@ response. server ");
}
// These static variables are used for simple breakpointing & other QuickExec rules
Static var bpRequestURI: String = null;
Static var bpResponseURI: String = null;
Static var bpStatus: int =-1;
Static var bpMethod: String = null;
Static var uiBoldURI: String = null;
Static var gs_ReplaceToken: String = null;
Static var gs_ReplaceTokenWith: String = null;
Static var gs_OverridenHost: String = null;
Static var gs_OverrideHostWith: String = null;
// The OnExecAction function is called by either the QuickExec box in the Fiddler window,
// Or by the ExecAction.exe command line utility.
Static function OnExecAction (sParams: String []) {
FiddlerObject. StatusText = "ExecAction:" + sParams [0];
Var sAction = sParams [0]. toLowerCase ();
Switch (sAction ){
Case "bold ":
If (sParams. Length <2) {uiBoldURI = null; FiddlerObject. StatusText = "Bolding cleared"; return ;}
UiBoldURI = sParams [1]; FiddlerObject. StatusText = "Bolding requests for" + uiBoldURI;
Break;
Case "bp ":
FiddlerObject. alert ("bpu = breakpoint request for uri \ nbpm = breakpoint request method \ nbps = breakpoint response status \ nbpafter = breakpoint response for URI ");
Break;
Case "bps ":
If (sParams. Length <2) {bpStatus =-1; FiddlerObject. StatusText = "Response Status breakpoint cleared"; return ;}
BpStatus = parseInt (sParams [1]); FiddlerObject. StatusText = "Response status breakpoint for" + sParams [1];
Break;
Case "bpv ":
Case "bpm ":
If (sParams. Length <2) {bpMethod = null; FiddlerObject. StatusText = "Request Method breakpoint cleared"; return ;}
BpMethod = sParams [1]. toUpperCase (); FiddlerObject. StatusText = "Request Method breakpoint for" + bpMethod;
Break;
Case "bpu ":
If (sParams. Length <2) {bpRequestURI = null; FiddlerObject. StatusText = "RequestURI breakpoint cleared"; return ;}
If (sParams [1]. toLowerCase (). StartsWith ("http: //") {sParams [1] = sParams [1]. Substring (7 );}
BpRequestURI = sParams [1];
FiddlerObject. StatusText = "RequestURI breakpoint for" + sParams [1];
Break;
Case "bpafter ":
If (sParams. Length <2) {bpResponseURI = null; FiddlerObject. StatusText = "ResponseURI breakpoint cleared"; return ;}
If (sParams [1]. toLowerCase (). StartsWith ("http: //") {sParams [1] = sParams [1]. Substring (7 );}
BpResponseURI = sParams [1];
FiddlerObject. StatusText = "ResponseURI breakpoint for" + sParams [1];
Break;
Case "overridehost ":
If (sParams. Length <3) {gs_OverridenHost = null; FiddlerObject. StatusText = "Host Override cleared"; return ;}
Gs_OverridenHost = sParams [1]. toLowerCase ();
Gs_OverrideHostWith = sParams [2];
FiddlerObject. StatusText = "Connecting to [" + gs_OverrideHostWith + "] for requests to [" + gs_OverridenHost + "]";
Break;
Case "urlreplace ":
If (sParams. Length <3) {gs_ReplaceToken = null; FiddlerObject. StatusText = "URL Replacement cleared"; return ;}
Gs_ReplaceToken = sParams [1];
Gs_ReplaceTokenWith = sParams [2]. Replace ("", "% 20"); // Simple helper
FiddlerObject. StatusText = "Replacing [" + gs_ReplaceToken + "] in URIs with [" + gs_ReplaceTokenWith + "]";
Break;
Case "select ":
If (sParams. Length <2) {FiddlerObject. StatusText = "Please specify Content-Type to select."; return ;}
FiddlerObject. UI. actSelectSessionsWithResponseHeaderValue ("Content-Type", sParams [1]);
MessageBox. Show (sParams [1]);
FiddlerObject. StatusText = "Selected sessions returning Content-Type:" + sParams [1] + ".";
If (FiddlerObject. UI. lvSessions. SelectedItems. Count> 0 ){
FiddlerObject. UI. lvSessions. Focus ();
}
Break;
Case "allbut ":
Case "keeponly ":
If (sParams. Length <2) {FiddlerObject. StatusText = "Please specify Content-Type to retain during wipe."; return ;}
FiddlerObject. UI. actSelectSessionsWithResponseHeaderValue ("Content-Type", sParams [1]);
MessageBox. Show (sParams [1]);
FiddlerObject. UI. actRemoveUnselectedSessions ();
FiddlerObject. UI. lvSessions. SelectedItems. Clear ();
FiddlerObject. StatusText = "Removed all but Content-Type:" + sParams [1];
Break;
Case "stop ":
FiddlerObject. UI. actDetachProxy ();
Break;
Case "start ":
FiddlerObject. UI. actAttachProxy ();
Break;
Case "cls ":
Case "clear ":
FiddlerObject. UI. actRemoveAllSessions ();
Break;
Case "g ":
Case "go ":
FiddlerObject. UI. actResumeAllSessions ();
Break;
Case "help ":
Utilities. LaunchHyperlink ("http://www.fiddler2.com/redir? Id = quickexec ");
Break;
Case "hide ":
FiddlerObject. UI. actMinimizeToTray ();
Break;
Case "nuke ":
FiddlerObject. UI. actClearWinINETCache ();
FiddlerObject. UI. actClearWinINETCookies ();
Break;
Case "show ":
FiddlerObject. UI. actRestoreWindow ();
Break;
Case "tail ":
If (sParams. Length <2) {FiddlerObject. StatusText = "Please specify # of sessions to trim the session list to."; return ;}
FiddlerObject. UI. TrimSessionList (int. Parse (sParams [1]);
Break;
Case "quit ":
FiddlerObject. UI. actExit ();
Break;
Case "dump ":
FiddlerObject. UI. actSelectAll ();
FiddlerObject. UI. actSaveSessionsToZip (CONFIG. GetPath ("Captures") + "dump. saz ");
FiddlerObject. UI. actRemoveAllSessions ();
FiddlerObject. StatusText = "Dumped all sessions to" + CONFIG. GetPath ("Captures") + "dump. saz ";
Break;
Default:
If (sAction. StartsWith ("http") | sAction. StartsWith ("www ")){
System. Diagnostics. Process. Start (sAction );
}
Else
FiddlerObject. StatusText = "Requested ExecAction:" + sAction + "not found. Type HELP to learn more .";
}
}
}

Now the "Web Sessions" list is much refreshed, but if we want to be idle, go to the blog garden homepage, the "Web Sessions" list contains several more blog garden homepage Json output, because Fiddler2 intercepts all requests/responses via IE by default. Can I make it show only requests/responses from the local machine? You only need to configure the Filter option of Fiddler2, as shown in.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.