power_settings_new
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.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

1 Answer

by (171 points)
+1 vote

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.
add
...