Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

1 like 0 dislike
343 views
by The go-to Tester (262 points)
retagged by
I have send a request to an api and got the 200 response. Getting json stucture as result.

My question is now to count the number of fields in the json result.

 

Example :

If my response json looks like :

{

id : 1,

member : 123,

type : google,

src : google

}

Here the count is '4'. Can you please suggeste me the method to count the feild.

1 Answer

1 like 0 dislike
by The go-to Tester (181 points)

You can store above into a sttring and seperate it by comma.

 

String myStr = "{id : 1,member : 123,type : google,src : google}";

String[] values = myStr
.replaceAll("\n","") // remove next line
.split(","); // seperate string by comma
 
 
 
Now you can print values.length which is equal to number of fields.
 
Hope that helps.


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...