正确地将字符串变量连接到 url [英] Concatenating a string variable to a url properly

查看:42
本文介绍了正确地将字符串变量连接到 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&section1='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+"&section1="+"'"+section1+"'";

我得到 java.lang.string 的值无法转换为 JSONArray...JSONException.所以很明显前一行肯定有问题.isbatchcode> 是一个整数变量,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&section1='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&section1='IT'.

推荐答案

我检查了变量 isBatchsection1.它们返回 null.修改了所需的内容.按预期工作.不再出现 JSONException.

I checked for the variables isBatch and section1.They were returning null.Modified what was needed.Worked as expected.No more JSONException.

这篇关于正确地将字符串变量连接到 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆