问题
I have parsed a JSON response and got the String below :
String queryString = "AQB=1&v1=somev1data&v25=somev25data&URL=http://www.someurl.com/configure/getvalues/request1=req1Passed&data2=somedataPassed&ce=UTF-8&ARB=1";
When i split the above queryString the output should be :
AQB=1
v1=somev1data
v25=somev25data
URL=http://www.someurl.com/configure/getvalues/request1=req1Passed&data2=somedataPassed
ce=UTF-8
ARB=1
NOTE :
queryString always changes and the URL parameters also always changes.
AQB,v1.....v30,p1....p30,ce,pre,pe,URL,ARB are all the predefined variable names.
回答1:
It is NOT possible unless the URL parameter is properly URL-encoded, so the "&" characters will be escaped in order not to be interpreted as field separators.
The string should be encoded like this:
String queryString = "AQB=1&v1=somev1data&v25=somev25data&URL=http%3A%2F%2Fwww.someurl.com%2Fconfigure%2Fgetvalues%2Frequest1%3Dreq1Passed%26data2%3DsomedataPassed&ce=UTF-8&ARB=1";
As it is formatted in your question, the string cannot be parsed successively.
回答2:
StringTokenizer st = new StringTokenizer(queryString, "&");
while (st.hasMoreTokens()) {
System.out.println(st.nextToken());
}
As another poster suggests, the only thing now left is to take care of the URL
来源:https://stackoverflow.com/questions/16543676/how-to-parse-this-querystring-which-is-a-resultant-of-json-response