Convert (Parse) URL parameteres to JSON in Java -
i have rest client delivers url parameters. cloud rest infrastructure accepts json format.
is there way convert (parse) url parameters json format in java?
example of url parameters:
data=data10&sensor=sensor10&type=type10 to json format like:
{"data":"data10","sensor":"sensor10","type":"type10"}
the solution
there no solution out of box, therefore practical develop method solve this.
here parameters json converter method:
public static string paramjson(string paramin) { paramin = paramin.replaceall("=", "\":\""); paramin = paramin.replaceall("&", "\",\""); return "{\"" + paramin + "\"}"; } results
method input:
data=data10&sensor=sensor10&type=type10 method return output:
{"data":"data10","sensor":"sensor10","type":"type10"}
Comments
Post a Comment