java - get value from json object in jsp -
i have java function return output in json format
{"loyalty_score":{"end value":0.0,"difference":0.0},"activity_level":{"end value":0.0,"difference":0.0}} i want fetch each value of object
i try below code
jsonobject json = new jsonobject(); json = fb.summary(); system.out.print("\n\n\n json"+json); //{"loyalty_score":{"end value":0.0,"difference":0.0},"activity_level":{"end value":0.0,"difference":0.0}} system.out.print( json.get("loyalty_score")); //{end value=0.0, difference=0.0} now how end value , difference?
you said json.get("loyalty_score") gives {end value=0.0, difference=0.0} , must again json object. can type cast string :
<% string jloyaltyscore = json.get("loyalty_score").tostring();%> now split jloyaltyscore using , delimeter.
<% string splitloyalty[] = jloyaltyscore .split("//,"); string splitagain[] = splitloyalty[0]. split("="); //splitting first elem again %> this give intended results: splitagain[0], splitagain[1].
Comments
Post a Comment