有做过采用json进行通信的客户端软件吗

xypopo 2011-07-15 02:37:28
我们现在android手机客户端和服务端用json通信,程序运行正常.
但用iphone,用json写,代码如下
NSString *str = @"{\"UserName\":\"ab@163.com\",\"Password\":\"qwerty\"}";
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.phonepa.net:8384/user/login"]
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:40];
[request setHTTPMethod: @"POST"];
[request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody: [str dataUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"str=%@", str);
NSLog(@"post data = %@", [request HTTPBody]);
NSURLResponse *response = nil;
NSError *error = nil;
NSData * data =[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

NSString* strRet = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"STRRET= %@", strRet);
[strRet release];


服务端返回错误信息:
>
<title>String 引用没有设置为 String 的实例。<br>参数名: s</title>
<style>
body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
pre {font-family:"Lucida Console";font-size: .9em}
.marker {font-weight: bold; color: black;text-decoration: none;}
.version {color: gray;}
.error {margin-bottom: 10px;}
.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
</style>
</head>

<body bgcolor="white">

<span><H1>“/”应用程序中的服务器错误。<hr width=100% size=1 color=silver></H1>

<h2> <i>String 引用没有设置为 String 的实例。<br>参数名: s</i> </h2></span>

<font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">

<b> 说明: </b>执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

<br><br>

<b> 异常详细信息: </b>System.ArgumentNullException: String 引用没有设置为 String 的实例。<br>参数名: s<br><br>

<b>源错误:</b> <br><br>

<table width=100% bgcolor="#ffffcc">
<tr>
<td>
<code>

执行当前 Web 请求期间生成了未经处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。</code>

</td>
</tr>
</table>

<br>

<b>堆栈跟踪:</b> <br><br>
梦回童年 22:24:17
html>
<head>
<title>String 引用没有设置为 String 的实例。<br>参数名: s</title>
<style>
body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
pre {font-family:"Lucida Console";font-size: .9em}
.marker {font-weight: bold; color: black;text-decoration: none;}
.version {color: gray;}
.error {margin-bottom: 10px;}
.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
</style>
</head>

<body bgcolor="white">

<span><H1>“/”应用程序中的服务器错误。<hr width=100% size=1 color=silver></H1>

<h2> <i>String 引用没有设置为 String 的实例。<br>参数名: s</i> </h2></span>

<font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">

<b> 说明: </b>执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

<br><br>

<b> 异常详细信息: </b>System.ArgumentNullException: String 引用没有设置为 String 的实例。<br>参数名: s<br><br>

<b>源错误:</b> <br><br>

<table width=100% bgcolor="#ffffcc">
<tr>
<td>
<code>

执行当前 Web 请求期间生成了未经处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。</code>

</td>
</tr>
</table>

<br>

<b>堆栈跟踪:</b> <br><br>
...全文
241 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
程序员小迷 2012-01-14
  • 打赏
  • 举报
回复
服务器要负责解析json?
那看看服务器怎么解析的,有没有问题。
flytheriver 2011-07-29
  • 打赏
  • 举报
回复
服务器因为空指针挂了,这个问题首先要找服务器开发人员来解决,调一下哪个变量挂了
但是可能是因为你少传递一个参数引起

这个问题是因为服务器考虑不周,让服务器先改!
ArthurChen 2011-07-15
  • 打赏
  • 举报
回复
要用json也用个专业一点吧,现在遍地都是开源库

29,031

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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