正确地将字符串变量连接到 url
这是从php json输出中删除换行符的后续问题.我不知道是什么导致了这个问题,但我以某种方式摆脱了 value <br ...JSONException
.
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
.
问题
当我使用
String url = "http://192.168.32.1/Aafois/notice.php?isBatch=2010§ion1='IT'";
我得到了我想要的东西,即将 JSON 解析为我的 android 应用程序.但是当我使用时
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+"§ion1="+"'"+section1+"'";
我得到 java.lang.string 的值无法转换为 JSONArray...JSONException
.所以很明显前一行肯定有问题.isbatch
code> 是一个整数变量,secton1
是一个字符串变量,它是 URL 编码为 utf-8
.
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
.
附注
我需要 单引号
'
在变量 section1
之前和之后,就像 url 一样http://192.168.32.1/Aafois/notice.php?isBatch=2010§ion1=
'IT'.
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§ion1=
'IT'.
我检查了变量 isBatch
和 section1
.它们返回 null.修改了所需的内容.按预期工作.不再出现 JSONException.
I checked for the variables isBatch
and section1
.They were returning null.Modified what was needed.Worked as expected.No more JSONException.