日期:2014-05-17  浏览次数:20442 次

神奇的字符串赋值现象,大神大侠大牛快来看啊,能解决者100分相送啊
如题,下面的代码,是拍拍API接口的调用代码,
getResponseString()方法的返回值列在下面的result后面了,以供参考。
神奇的是,这个返回值,用第一个方法接受,可以正确的赋值给textBox8,
采用第2个方法接收返回值,tmpStr接收不到值,
会直接跳出本方法,try{}catch{}也捕获不到错误!!!!
C# code

try
{
    this.client.SetSKey(this.textSKEY.Text);
    this.client.SetSpid(this.textSPID.Text);
    this.client.SetUin(Convert.ToInt32(this.textUIN.Text));
    this.client.SetToken(this.textTOKEN.Text);
    this.client.invokeApi(this.textBox7.Text);
    //1>可以正常赋值
    this.textBox8.Text = this.client.getResponseString();
    //2>不可赋值,也不报错,直接跳出方法,catch也捕获不到错误
    string tmpStr = this.client.getResponseString();       
}
catch(Exception ex)
{
}
result:
[this.textBox8.Text = "try { sellerSearchDealListSuccess(\r\n{\r\n\"errorCode\":8193,\r\n\"errorMessage\":\"必须填写卖家的QQ号\"\r\n}\n\r\n);}catch(e1){try{sellerSearchDealListFail(e1);}catch(e2){}}\r\n"]


目前初步怀疑是这个返回值有什么特别的地方,
导致不能赋值给string变量,
但是又看不出来哪里不对,
请各位大神大牛大侠救命.....


------解决方案--------------------
呵呵,是有点怪怪的
能直接数出来吗?
Console.Write(this.client.getResponseString());
或者
Response.Write(this.client.getResponseString());
------解决方案--------------------
tmpStr 不被任何地方继续使用,vs优化不处理
------解决方案--------------------
探讨

呵呵,是有点怪怪的
能直接数出来吗?
Console.Write(this.client.getResponseString());
或者
Response.Write(this.client.getResponseString());

------解决方案--------------------
textbox8.text都能得到值、string tmpstr怎么可能得不到值啊。

你把textbox8.text 与tmpstr的值打印出来看看!没错try catch 如何给报错啊!
------解决方案--------------------
你把try。。。catch。。。。删除如何
------解决方案--------------------
探讨

找到问题原因了,
是编码格式导致的,
this.client.invokeApi(this.textBox7.Text);
这个this.textBox7.Text的值是Url,
在这个url后面追加"?charset=utf-8"
就可以了。

不过虽然业务问题解决了,
技术问题还是很不解,
为什么会这样呢。。。。。