- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发一个 iOS 应用程序,它使用用 java 编写的网络服务。该应用程序向该 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>
所以在我的 servlet 中我这样做
String req = request.getParameter("data");
但很明显,当我尝试打印它时,我得到了上面的字节。
如何将此类数据转换为初始 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");
希望这会有所帮助..:)
关于java - 将 NSData 转换为 Java 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25602284/
我有一个相当大的 NSData (或 NSMutableData 如果需要)对象,我想从中取出一小块并保留其余部分。由于我正在处理大量 NSData 字节,因此我不想制作大副本,而只是截断现有字节。基
我有一个 NSMutableData 保存随机 ASCII 字节。 我想将这些字节的值移动一个值(X)。 所以让我们说我有这样的事情: 02 00 02 4e 00 我现在想将每个字节增加 0x01
我有一个NSData对象,其中包含图像的 RGB 值。我想把它变成 UIImage (给定宽度和高度)。然后我想转换 UIImage回到NSData对象与我开始时的对象相同。 请帮助我,我已经尝试了几
在做了类似的事情之后 NSData *originalImageData = [NSData dataWithContentsOfFile:@"somefolder\somepicture.jpg"]
我有两个 NSData 对象 NSData *toScan = /* initialized somehow with "Hello, this world." */; NSData *toMatch
我有一个 NSData 对象,其中包含我需要的一些数据。我想做的是找出数据“FF D8”的位置(JPEG数据的开始) 我怎样才能完成这样的工作? 最佳答案 先获取范围,然后获取数据: // The m
在基础框架中对内置的 NSData 类调用散列时——使用什么实现来返回散列值? (CRC32,还有什么?) 最佳答案 别的。其实就是一个实现细节,不需要在不同的版本中使用固定的算法。 你可以在Core
在基础框架中对内置的 NSData 类调用散列时——使用什么实现来返回散列值? (CRC32,还有什么?) 最佳答案 别的。其实就是一个实现细节,不需要在不同的版本中使用固定的算法。 你可以在Core
我收到错误: NSData 不是我下面代码中 NSData 的子类型,我做错了什么? let urlPath = "myurl" var url = NSURL(string: urlPath) le
我有一个大小约为 1000kB 的 NSData 对象。现在我想通过蓝牙传输这个。如果我有 10 个 100kB 的对象,那就更好了。我想到我应该使用 NSData 的 -subdataWithRan
我的 NSData 格式为“Hello$World$Image”($ 用作分隔符来区分不同的部分数据)我使用以下代码制作的 NSData *data=[@"$" dataUsingEncoding:N
我有两个 NSData 对象,我想将它们存储在第三个 NSData 对象中。我的想法是,当我稍后解码较大的对象时,我希望能够轻松地获得彼此独立的两个较小的对象,而不用担心它们的相对大小或数据类型。 看
我想将图像添加到字节数组。下面的代码给我一个错误。我想我没有做对。 错误 Field has incomplete type 'NSData *__strong[]' 在.m文件中 @interfac
我遇到了问题,你能帮帮我吗?太感谢了!NSString *我的字符串;UIImage *图像;NSData *data = ... 包括字符串和图像的数据,可以像以前一样反编译它们 最佳答案 您可以按
我觉得上面的错误一定是 Swift 的一个错误,否则 1 != 1 是一个正确的陈述... 我正在尝试创建一个 JSONObject,我可以将其包含在 HTTP Post 请求的正文中,以便使用 Co
我正在尝试将两个 NSData 对象连接成一个 NSMutableData,然后将它们取回。现在我正在尝试以这种方式进行: 获取第一个对象的长度。 按以下顺序写入 NSMutableData:第一个对
我想将 [String] 转换为 NSData 以进行 BLE 连接。 我知道如何将 String 转换为 NSData/NSData 为 String。 // String -> NSData va
这是我正在尝试的代码 NSData *imageData = [[NSData alloc]initWithData:UIImagePNGRepresentation(myImage.image)];
例如: NSData *data = [NSData dataWithContentsOfFile:filePath]; int len = [data length]; 如果 len = 10000
NSData 和 NSMutableData 有什么区别? 最佳答案 来自 Stack Overflow 标签维基: nsdata The NSData class is an apple class
我是一名优秀的程序员,十分优秀!