This is a migrated thread and some comments may be shown as answers.

How to check if the json is successfully parsed ?

2 Answers 525 Views
Fiddler Classic
This is a migrated thread and some comments may be shown as answers.
lff
Top achievements
Rank 1
lff asked on 06 Mar 2019, 02:15 AM

Hi 

Now I am running with

var oJSON = Newtonsoft.Json.JsonConvert.DeserializeObject(oS.GetRequestBodyAsString());
var t = oJSON.JSONObject["target"]

........

But sometimes the oS.GetRequestBodyAsString() is not a valid json string.

Is there any way to check the oJSON status to see if the job is done without errors?

For example,

var oJSON = Newtonsoft.Json.JsonConvert.DeserializeObject(oS.GetRequestBodyAsString());

if (!oJSON.isSuccessful) {

    // process error and return

2 Answers, 1 is accepted

Sort by
0
lff
Top achievements
Rank 1
answered on 06 Mar 2019, 02:23 AM

Sorry the above was my test code (does not work). It should be

var oJSON = Fiddler.WebFormats.JSON.JsonDecode( oS.GetRequestBodyAsString());

0
lff
Top achievements
Rank 1
answered on 06 Mar 2019, 02:37 AM

Seems to find out:

if (oJSON.JSONObject == null) {
    // process error and return

Tags
Fiddler Classic
Asked by
lff
Top achievements
Rank 1
Answers by
lff
Top achievements
Rank 1
Share this question
or