-1

我正在尝试解析 json。我收到以下异常:

An exception of type 'System.ArgumentException' occurred in Newtonsoft.Json.Silverlight.DLL but was not handled in user code

我的 C# 代码是

private void imgloginbtn_Tap_1(object sender, 
                               System.Windows.Input.GestureEventArgs e) {
  ///set flag in app.xaml for popup
  var obj = App.Current as App;
  obj.Popupflag = true;
  //WhatsupServices.WhatsUpServiceSoapClient ws = 
                    //new WhatsupServices.WhatsUpServiceSoapClient();
  WhatsupServices.WhatsUpServiceSoapClient ws = 
                  new WhatsupServices.WhatsUpServiceSoapClient();
  ws.ChangePasswrdJsonCompleted += ws_ChangePasswrdJsonCompleted;
  ws.ChangePasswrdJsonAsync("man", "man", "man");
}
void ws_ChangePasswrdJsonCompleted(object sender, 
                 WhatsupServices.ChangePasswrdJsonCompletedEventArgs e) {
  string s = e.Result;
  JObject obj = JObject.Parse(s);
  string ResultCode = (string) obj["ResultCode"];
  string ResponceMessage = (string) obj["ResponseMessage"];
}

当我试图获取 Resultcode 时发生异常

帮助我如何解决这个问题?

4

1 回答 1

0

我得到了这个异常的解决方案。实际上我的 json 返回值是整数,我正在字符串中进行类型转换,所以它给出了错误。

我的解决方案是:

string s = e.Result;
  JObject obj = JObject.Parse(s);
  int ResultCode = (int) obj["ResultCode"];
  string ResponceMessage = (string) obj["ResponseMessage"];
于 2013-04-26T08:49:49.620 回答