我们现在android手机客户端和服务端用json通信,程序运行正常.
但用iphone,用json写,代码如下
 NSString *str = @"{\"UserName\":\"[email protected]\",\"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}
         .er {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}
         .er {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>