How to parse this queryString which is a resultant of JSON response [closed]

帅比萌擦擦* 提交于 2019-12-25 19:08:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!