将NSData转换为Java字符串

将NSData转换为Java字符串,java,ios,json,bytearray,nsdata,Java,Ios,Json,Bytearray,Nsdata,我正在开发一个iOS应用程序,它使用java编写的web服务。 应用程序向该web服务器发出POST请求,发送一个由JSON创建的NSData对象,例如: <7b22636c 69656e74 223a7b22 656e7669 726f6e6d 656e7422 3a227361 6e64626f 78222c22 70726f64 7563745f 6e616d65 223a2250 61795061 6c20694f 53205344 4b222c22 70617970 616c5f

我正在开发一个iOS应用程序,它使用java编写的web服务。 应用程序向该web服务器发出POST请求,发送一个由JSON创建的NSData对象,例如:

<7b22636c 69656e74 223a7b22 656e7669 726f6e6d 656e7422 3a227361 6e64626f 78222c22 70726f64 7563745f 6e616d65 223a2250 61795061 6c20694f 53205344 4b222c22 70617970 616c5f73 646b5f76 65727369 6f6e223a 22322e32 2e31222c 22706c61 74666f72 6d223a22 694f5322 7d2c2272 6573706f 6e73655f 74797065 223a2270 61796d65 6e74222c 22726573 706f6e73 65223a7b 22696422 3a225041 592d3233 44393230 32375545 36383337 3034304b 51434337 5859222c 22737461 7465223a 22617070 726f7665 64222c22 63726561 74655f74 696d6522 3a223230 31342d30 392d3031 5430383a 33353a34 335a222c 22696e74 656e7422 3a227361 6c65227d 7d>
但很明显,当我试图打印它时,我得到了上面的字节

如何将这些数据转换为初始JSON

编辑1: 我用这种方式发送NSData

    NSData *confirmation = [NSJSONSerialization dataWithJSONObject:completedPayment.confirmation
                                                           options:0
                                                             error:nil];

    NSURL *url = [NSURL URLWithString:@"MY_WS"];

    NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
    NSString *messageBody = [NSString stringWithFormat:@"data=%@", confirmation];
    [theRequest setHTTPMethod:@"POST"];
    [theRequest setHTTPBody:[messageBody dataUsingEncoding:NSUTF8StringEncoding]];
    NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

我想我不能直接发送JSON字符串…

不确定NSData,但如果你能得到byte[]数组,你可以将它传递给sting构造函数

String javaStringRep = new String(theByteArray, "UTF-8");

希望这有帮助:)

为什么不发送JSon?请看:@Yasika这不是我需要的。我已经看过那张字符串表了。我需要的是将包含字节的字符串转换为包含JSON的字符串!
String javaStringRep = new String(theByteArray, "UTF-8");