Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
175 views
in Technique[技术] by (71.8m points)

java - Concatenating a string variable to a url properly

This is a follow up question of Removing linebreak from php json output.I couldn't find out what was making that problem but i somehow got rid of value <br ...JSONException.

The Issue

when i use

String url = "http://192.168.32.1/Aafois/notice.php?isBatch=2010&section1='IT'";

I get what i want i.e parsing the JSON to my android app.However when i use

String URL="http://192.168.32.1/Aafois/notice.php?isBatch="+isbatch+"&section1="+"'"+section1+"'";

I get Value of java.lang.string can't be converted to JSONArray...JSONException.So obviously there must be some problem there in this previous line.isbatch is an integer variable and secton1 is a string variable which is URL encoded to utf-8.

P.S

I need single quote ' before and after the variable section1 as the url goes like http://192.168.32.1/Aafois/notice.php?isBatch=2010&section1='IT'.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think of your variables is a JSONArray. To concatenate everything, it tries to turn your String into a JSONArray, which is not possible as your string is not JSON but part of a URL.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...