[英]responseString is null
my webservice returns json string with new lines so It causes problem that responseString gives always null. 我的网络服务返回带有新行的json字符串,因此它引起问题,即responseString始终为null。
NSString *responseString=[[NSString alloc] initWithData:kampanyadata encoding:NSUTF8StringEncoding];
NSLog(@"%@",[NSString stringWithFormat:@"responsestring:%@",responseString]);
----responsestring:null
---- responsestring:null
how can I replaces new lines character in JSON String? 如何替换JSON字符串中的换行符?
NSString *tempString = [tempString stringByReplacingOccurrencesOfString:@"\n" withString:@" "];
我认为您需要这样做:)
Are you sure kampanyadata is not null? 您确定kampanyadata不为null吗? If it's not null try to use
NSASCIIStringEncoding
like this: 如果不为null,请尝试使用
NSASCIIStringEncoding
如下所示:
NSString *responseString=[[NSString alloc] initWithData:kampanyadata encoding:NSASCIIStringEncoding];.
Offtopic 题外话
And btw the NSLog();
然后通过
NSLog();
method takes a NSString formatted already as parameter so you can use: 方法采用已经格式化的NSString作为参数,因此您可以使用:
NSLog(@"responsestring:%@",responseString);
soapResults = [[NSString alloc]
initWithBytes: [webData mutableBytes]
length:[webData length]
encoding:NSUTF8StringEncoding];
try this this works fine for me 试试这个对我来说很好
You got some NSData, and you tried to convert it to an NSString. 您获得了一些NSData,然后尝试将其转换为NSString。 There's no JSON involved at this point.
此时不涉及JSON。 Any errors have nothing to do with JSON or newline characters whatsoever.
任何错误都与JSON或换行符无关。 Possibilities: 1. The NSData that you received is nil.
可能性:1.您收到的NSData为零。 2. The NSData that you received isn't in UTF-8 format.
2.您收到的NSData不是UTF-8格式。
Your NSLog statement is quite funny. 您的NSLog语句很有趣。 Look at the definition of NSLog - the first parameter is a format string.
查看NSLog的定义-第一个参数是格式字符串。 Instead of
代替
NSLog(@"%@",[NSString stringWithFormat:@"responsestring:%@",responseString]);
you should write 你应该写
NSLog (@"responseString:%@", responseString);
And you can pass the JSON document directly to NSJSONSerializer. 您可以将JSON文档直接传递给NSJSONSerializer。 No need to convert it to an NSString.
无需将其转换为NSString。 Actually, if the data is large, just a waste of valuable memory.
实际上,如果数据很大,那只会浪费宝贵的内存。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.