Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java中的字符串公式_Java_String_Http_Url - Fatal编程技术网

Java中的字符串公式

Java中的字符串公式,java,string,http,url,Java,String,Http,Url,我需要在javaME中编写一个URL字符串(这不允许我在短时间内处理许多库),就像这样 url = "http://helloworld.com/index.php?data={\"Word\":"+wordX+",\"RS\":20/04/13-2008:31:44,\"SER\":"+net2+"}"; 这是一个字符串,如下所示: http://helloworld.com/index.php?data={"Word":358741051173885,"RS":20/04/13

我需要在javaME中编写一个URL字符串(这不允许我在短时间内处理许多库),就像这样

     url = "http://helloworld.com/index.php?data={\"Word\":"+wordX+",\"RS\":20/04/13-2008:31:44,\"SER\":"+net2+"}"; 
这是一个字符串,如下所示:

http://helloworld.com/index.php?data={"Word":358741051173885,"RS":20/04/13-2008:31:44,"SER":53543d303b44523d4e616fd}
问题是我需要值也在逗号内。我什么都试过了,但我不知道怎么做。 有人能解释一下吗


谢谢

创建一个
消息格式

final MessageFormat urlFormat = new MessageFormat("http://helloworld.com/index.php?data={\"Word\":\"{0}\",\"RS\":20/04/13-2008:31:44,\"SER\":\"{1}\"}");
final String url = String.format(urlFormat, wordX, net2);
然后只需将值应用于格式:

final String url = urlFormat.format(new Object[]{wordX, net2});
或者,创建一个格式
字符串

final String urlFormat = "http://helloworld.com/index.php?data={\"Word\":\"%s\",\"RS\":20/04/13-2008:31:44,\"SER\":\"%s\"}";
并使用
String.format

final MessageFormat urlFormat = new MessageFormat("http://helloworld.com/index.php?data={\"Word\":\"{0}\",\"RS\":20/04/13-2008:31:44,\"SER\":\"{1}\"}");
final String url = String.format(urlFormat, wordX, net2);
或者,只需将您的
String
更改为:

url = "http://helloworld.com/index.php?data={\"Word\":\""+wordX+"\",\"RS\":20/04/13-2008:31:44,\"SER\":\""+net2+"\"}"; 
像这样

String url = String.format("http://helloworld.com/index.php?data={\"Word\":\"%s\",\"RS\":20/04/13-2008:31:44,\"SER\":\"%s\"}", wordX, net2);

“我需要值也在逗号内”。请举例说明。为什么不使用众多json库中的一个呢?例如jackson?你的意思是也应该引用值吗<代码>http://helloworld.com/index.php?data={“Word”:“358741051173885”,“RS”:“20/04/13-2008:31:44”,“SER”:“53543d303b44523d4e616fd”}我希望这是你所期待的。。String str=“{\'Word\':\'358741051173885\',\'RS\':\'20/04/13-2008:31:44\',\'SER\':\'53543d303b44523d4e616fd\'”;这正是我想要的,但是声明变量名WordX和Net2而不是传递值!我不能这样做,因为这是针对javaME项目的,这意味着不使用任何高于1.3jre的东西。我忘了在问题中提到它。我的错@这是一个小小的重大遗漏,你不觉得吗?!的确如此!haha@kohhworlwide我添加了最后一个选项,应该对你有用。太好了!谢谢你,鲍里斯!万圣节快乐,哈哈。