ASIHTTP请求的数据解析出错问题Error Domain=NSCocoaErrorDomain Code=3840 "Unable to convert data to string around

AFNetworking,处理返回数据时出现Error Domain=NSCocoaErrorDomain Code=3840 错误 报错: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Unescaped control character around character 2884.) UserInfo=0x79fa60b0 {NSDebugDescription=U 阅读详情

Error Domain=NSCocoaErrorDomain Code=3840 "Unable to convert data to string around character 347." UserInfo={NSDebugDescription=Unable to convert data to string around character 347.}

这个问题一般是数据格式非utf8造成的。

解决方法是:先把返回的nsdata数据转为nsstring,然后对string编码,再转回nsdata,然后就可以用json正常解析了。

实现如下:

NSError * error;

        NSStringEncoding enc = kCFStringEncodingUTF8;

        NSString* strdata = [[NSString alloc]initWithData:temp.responseData encoding:enc];//在将NSString类型转为NSData

        NSData * data = [strdata dataUsingEncoding:NSUTF8StringEncoding];//这样解决的乱码问题。

        NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error ];


Win 11 Fastboot驱动的详细安装教程 Fastboot驱动的详细安装教程 阅读详情

相关推荐

HFSS实战(二)——精准仿真高速PCB差分线的信号完整性

本文深入探讨了使用HFSS进行高速PCB差分线信号完整性仿真的关键技术与实战经验。从设计文件导入、模型裁剪到差分端口设置,详细解析了精准仿真的全流程,特别强调了材料特性和3D电磁场仿真在解决微带线损耗等问题中的重要性。文章还提供了常见问题排查指南和效率优化技巧,帮助工程师提升高速PCB设计的仿真精度与效率。

weixin_38170829的博客 572

Ios解析java返回的数据报错,IOS 原生解析JSON 问题

服务器----WebService返回的是JSON数据 IOS解析报错:Error Domain=NSCocoaErrorDomain Code=3840 "Unable to convert data to string around character 56." UserInfo={NSDebugDescription=Unable to convert data to string arou...

weixin_29489791的博客 519

Cisco思科 电子科技大学计算机网络 SRWE 期末技能考试 (PTSA)

电子科技大学2024春_SRWE_计算机网络系统 SRWE 期末技能考试 (PTSA)

2301_76745065的博客 5094

Error Domain=NSCocoaErrorDomain Code=3840解决方法

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];

z_5502110036的博客 3650

Grok 3国内怎么用?超详细使用指南+实用指令模板

主要是用于快速分析学术论文,提取关键信息,总结研究成果。Analyze the following research paper: [粘贴或上传论文内容]1. Extract key findings, methodologies, and conclusions. (提取主要发现、方法和结论。2. Identify statistical significance and data points. (识别统计显著性和数据点。

Survivor_sl的博客 1万+

【数据集】中国区域地面气象要素驱动数据集(CMFD)2.0

中国区域地面气象要素驱动数据集(CMFD)2.0

WW、forever的博客 2979

Error Domain=NSCocoaErrorDomain Code=3840 “No value.“

描述 客户端请求服务端接口,接口返回`Error Domain=NSCocoaErrorDomain Code=3840 “No value.”。 原因 客户端解析JSON出错 如果是使用AF报3840的错误的话,使用不当会报3840的错误,原因是Json不能解析。 服务端返回的JSON格式有问题 返回空或者没任何返回,或者JSON格式问题等导致没法解析。 GET请求中长度超限制 有遇到过这种情况就是,接口用的是GET请求,请求中有一个参数,这个参数的数据量会随着业务变化,之前一直没发现问题,后

竹毛言己 3655

前后端面试题【目录】

工作时候扭螺丝,面试时候造火箭,现状就是如此。不管是背八股文,还是掌握了知识的精华,对答如流才是硬道理。本专栏就是要集具前端精华,规范、算法、架构、封装、原理等一并汇集,让前端的小伙伴有个思路。, 欢迎一起交流,并非常期望您能够提供有价值的学习资料。

大剑师兰特的GIS世界 1835

iOS Error Domain=NSCocoaErrorDomain Code=3840 解析带等号(=)的json字符串

解析json字符串的时候报错: 第一个字符应该是key的字符串。

baidu_40537062的博客 1362

GB28181 —— 3、C++编写GB28181设备端,完成注册、注销、保活心跳、响应查询目录等功能(附源码)

GB28181 —— Win10下编写GB28181设备端,完成注册、注销、保活心跳、响应查询目录等功能(附源码)

1308

【七.三维视觉与视频分析】【1.点云处理:PointNet++/PointTransformer】

各位老铁,今天咱们要聊的可不是普通的二维图像处理,而是三维视觉领域最硬核的技术——点云处理。从最早的PointNet到如今的PointTransformer,这场技术进化堪比三维版的"像素革命"。今天咱们就深入解剖两大里程碑:PointNet++和PointTransformer,保证让你看完全文就能在点云领域横着走!想象一下,你抓了把沙子撒在空中,每粒沙子的位置都是三维坐标——这就是点云的典型形态。最后送大家一句话:点云处理就像在三维宇宙中寻找星辰的轨迹,既要望远镜的宏观视野,也要显微镜的细致入微。

商务合作|问题讨论|交流学习 请联系作者微信,加微信请务必注明来意,博客主页有联系方式 473

json解析 Code=3840问题

一般说来产生这个问题常见原因有两个一、是否因为编码问题导致json字符串没有正确获取。打个断点调试一下,看data能否转成str。这种情况多是因为后台或者本地的文件编码格式有问题。比如是ascii而你是按照utf8解析。二、是否因为json本身有问题。可能json的格式不对。可以百度下bejson等验证一下。比如中英文符号等等。

args_的博客 3793

【LLC快速上手系列】LLC轻载时,死区时间怎么调才对?别再傻傻乱搞了!

死区时间,就是指。如果你死区设得好,就能让开通前 ( V_DS to 0 ),完美实现!

weixin_43199439的博客 1856

Http 3840 错误

Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set." UserInfo={NSDebugDescription=JSON text did not start with array or objec

jeffasd的专栏 5060

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Error Domain=NSCocoaErrorDomain Code=3840Json解析失败

今天调用:  NSDictionary *dic= [NSJSONSerialization JSONObjectWithData:[result dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:&error];时失败,报: Error Domain=NSCocoaErrorDomain Code=38

wangjie33589的博客 6538

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

ios af 返回html,iOS使用AFNetworking遇到3840错误的解决方法

释放双眼,带上耳机,听听看~!总结一个工作中遇到的坑。后端返回的JSON明明是成功,但是始终被解析为错误,并返回3840错误。这个错误通常是因为返回的数据格式不正确,但是抓包显示的确是JSON串,但是在JSON串之前有15行是空白的!!!!开始认为是后端数据的问题,跟后端哥们调试了6个小时无果,最后还是得前端自己解决。第一个想法就是将返回的JSON文本去首尾空行空格再进行序列化。于是,在失败的bl...

weixin_30015371的博客 879

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

AFNetworking 请求报错 NSCocoaErrorDomain Code=3840 查看Response数据

Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x91...

nadeal在写博客 2742

Domain=NSCocoaErrorDomain Code=3840 "Unescaped control character around character 203." UserInfo={NS

error = Error Domain=NSCocoaErrorDomain Code=3840

yiral的博客 4350

网络服务器调试报错:code = -1011 code = 3840

Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0., NSUnderlyingError=0x7fe90b5a6830 {Error Domain=com.alamofir

极客学伟的技术分享社区 8893

解决AFN的post请求错误:Error Domain=NSCocoaErrorDomain Code=3840

Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x

Logan_017的空间 2万+

AFNetwork在请求时报错code=-1016 和 3840?

1》在进行网络请求时出现-1016,是因为只支持text/json,application/json,text/javascript,可以添加text/html  在进行网络请求时出现3840,添加如下语句: manger.requestSerializer = [AFHTTPRequestSerializer serializer]; manger.responseSerializer =

桥边风满袖的博客 2411

IOS 中json解析异常Domain=NSCocoaErrorDomain Code=3840之诡异事件

前言 就在今天遇到一个很诡异的技术问题,Unity调用Quick苹果SDK支付。Quick 支付需要游戏(Unity)传入一些数据到原生OC中,格式是json,在OC中打印的日志看着数据是没问题的,但是解析json却一直显示失败 。问题最终还是解决了,用倒推法给大家说一下解决的思路。 场景重现 下面代码是OC中定义的支付方法,void *payData是接Unity中传过来的支付json数据,当用户点击支付按钮的时候,Unity把支付的数据传到IOS 原生OC中。没有了解过的可以看下之前写过的文章 :Un

北京朝阳区精神病院院长 2951

未能连接服务器端3840,objective-c

我正在尝试将数据发送到服务器并以JSON格式接收响应。 问题是服务器必须返回“成功”或“失败”,但它返回“(null)”。这是返回的错误:Error Domain = NSCocoaErrorDomain Code = 3840“操作无法完成。(Cocoa error 3840。)”(JSON文本不是以数组或对象开头,而是选项允许未设置片段。)UserInfo = XXXXXXXXX {NSDe...

weixin_42468245的博客 251

iOS-Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be complet

在用AFN获取的JSON字符串中可能会报如上错误,原因是json数据当中有 \n \r \t 等制表符。由于标准的json解析是不允许有这几个制表符的。所以在解析之前我们需要把这几个制表符给过滤掉。 NSString * responseString = [request responseString]; responseString = [responseString stringByRe

极客学伟的技术分享社区 2125

AFNetworking数据请求错误 Code=3840

欢迎使用Markdown编辑器写博客本Markdown编辑器使用StackEdit修改而来,用它写博客,将会带来全新的体验哦: Markdown和扩展Markdown简洁的语法 代码块高亮 图片链接和图片上传 LaTex数学公式 UML序列图和流程图 离线写博客 导入导出Markdown文件 丰富的快捷键 快捷键 加粗 Ctrl + B 斜体 Ctrl + I 引用 Ctrl

大妹子程序○ 1万+

iOS开发Post请求错误:Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or ...

由于最近忙着开发项目,好几天没来写博客了。我把最近遇到的一个小bug来和大家分享一下。      最近iOS开发中,客户端需要使用http POST去进行请求服务器。需要发送的是XML格式的,当然接收的也是XML。我们准备使用的是AFNetworking来实现。关于AFnetworking的使用以及Cocoapods包管理,请参考我的其他几篇博客:《iOS项目开发实战——使用AFNetworki

乞力马扎罗的雪CYF的博客 4万+
上一篇: 杂项小记
下一篇: http缓存策略
hypercode
博客等级 码龄19年 24粉丝 46原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值