从web服务传到j2me的string数据丢失,急急急!

biewenwomima 2010-10-12 11:59:54
从web服务传到j2me的string数据丢失,如果在web服务里面直接写
return"返回结果";
就可以j2me模拟器端接收到
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">返回结果</string>
但是如果定义一个
string result="返回结果";
return result;
但在j2me模拟器端接收到的却是:
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/" />

应该返回的结果:"返回结果"不见了
跪求各位高手帮忙,谢谢了


...全文
76 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Nico 2010-10-15
  • 打赏
  • 举报
回复
仔细看下你的解析代码部分有没问题
biewenwomima 2010-10-14
  • 打赏
  • 举报
回复
哈哈,如果能解决,感激不尽!!!
biewenwomima 2010-10-14
  • 打赏
  • 举报
回复
我的web函数写的是这样的:
:[WebMethod(
Description = "自助导游,帮您做自己的导游!")]
public string DIYTravel(string s,string i)
{ string colum="Text";
string result = "";
switch (i){

case "0":colum="Text";break;
case "1":colum="Voice";break;
case "2":colum="Vidio";break;
}
string sql = "select "+colum+" from ScenerySpot where Name='"+s+"'";
SqlDataAdapter da = new SqlDataAdapter(sql, c);
DataTable tbl = new DataTable("result");
da.Fill(tbl);
foreach (DataRow row in tbl.Rows)
{
result = row[colum].ToString();
}
return result;

}
biewenwomima 2010-10-14
  • 打赏
  • 举报
回复
好像不是,我直接用这段代码调用web服务里面的方法,
conn=(HttpConnection)Connector.open(this.serverURL);

conn.setRequestProperty("content-type", "text/html;charset=gb2312");

int contentLength=(int)conn.getLength

byte[]content=new byte[contentLength];

DataInputStream dis=conn.openDataInputStream();

String isOK=conn.getResponseMessage();

if(isOK.equals("OK")){

dis.readFully(content, 0, content.length);

String res=new String(content,"UTF-8");

System.out.println(res);
}

最后就只能在output窗口中显示:
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/" />

但是如果在电脑浏览器上用HTTPpost调用显示的是:

<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">[color=#FF0000]西安是我国著名的…
</string>[/color]
其中“西安是我国著名的…”是web服务里面的函数返回的值
这是怎么回事啊,谢谢了
「已注销」 2010-10-13
  • 打赏
  • 举报
回复
是不是方法的返回值,赋值给某个变量后,又被修改了?在返回客户端之前

一般来说,不可能出现字符串中间少内容的情况
biewenwomima 2010-10-13
  • 打赏
  • 举报
回复
是的,请问高手如何解决,谢谢了
麦田捕手 2010-10-13
  • 打赏
  • 举报
回复
问题有点含糊不清,不过我猜可能是String res=new String(content,"UTF-8")的res为空字符串“”了
biewenwomima 2010-10-13
  • 打赏
  • 举报
回复
j2me模拟器端代码片段:
try{

conn=(HttpConnection)Connector.open(this.serverURL);
conn.setRequestProperty("content-type", "text/html;charset=gb2312");

int contentLength=(int)conn.getLength();

byte[]content=new byte[contentLength];
DataInputStream dis=conn.openDataInputStream();
String isOK=conn.getResponseMessage();
System.out.println("1");
System.out.println(isOK);
if(isOK.equals("OK")){
dis.readFully(content, 0, content.length);
String res=new String(content,"UTF-8");
System.out.println(res);
this.result=this.manipulationResult(res);
System.out.println(result);
}else{
System.out.println("服务器连接失败");
}

}catch(IOException e){
e.printStackTrace();
}
服务端代码片段:[WebMethod(
Description = "自助导游,帮您做自己的导游!")]
public string DIYTravel(string s,string i)
{ string colum="Text";
string result = "";
switch (i){

case "0":colum="Text";break;
case "1":colum="Voice";break;
case "2":colum="Vidio";break;
}
string sql = "select "+colum+" from ScenerySpot where Name='"+s+"'";
SqlDataAdapter da = new SqlDataAdapter(sql, c);
DataTable tbl = new DataTable("result");
da.Fill(tbl);
foreach (DataRow row in tbl.Rows)
{
result = row[colum].ToString();
}
return result;

}
请各位高手多多帮忙,谢谢了

13,097

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧