Issue
I'm doing a webservice in java and in the post method i need to receive a json from the front-end
And my doubt is that i can read dynamically json
Lets pretend that sometimes i receive this
'{ "bit1":"000", "bit2":"1111", "bit50":"010101" }';
and in the next day i receive something like that:
'{ "bit3":"101", "bit7":"00010", "bit30":"1010111", "bit40":"1010001" }';
I dont know what the webservice will receive, the length, the name of the params, i only know that is a json well formed. There are any way to read it?
Thanks for your time
Solution
@Post
@Consume("application/json")
@Produce("application/json")
public String recieveMyJson(JSONObject myJSON)
{
// here myJSON will recieve any valid json structure regardless to the length
String []string=myJSON.toString().split(","); // should do what do you need
for(String myKey:string)
{
System.out.println(myKey)
}
}
Answered By - Basil Battikhi
Answer Checked By - Terry (JavaFixing Volunteer)