objective-c - iOS UITextView 忽略 JSON 响应中的换行符

标签 objective-c ios json uitextview

我需要在我的 iOS 应用程序中的 UITextView 中显示来自 JSON Webservice 的一些数据,该 UITextView 是多行的,但是当我在 TextView 上使用字符串时,新行不起作用。

这是我正在使用的代码:

// Data Value from JSON = testing the data value \r\n Another \n liine maybe?
NSString *responseDataString = [dictRequestorDetails objectForKey:@"data"];
txtWorkflowDetails.text = responseDataString;

当我执行此代码时,UITextField 显示

testing the data value \r\n Another \n liine maybe?

但是如果我输入类似的字符串

// Data Value from JSON = testing the data value \r\n Another \n liine maybe?
NSString *responseDataString = [dictRequestorDetails objectForKey:@"data"];
txtWorkflowDetails.text = @"testing the data value \r\n Another \n liine maybe?";

换行符然后在 TextView 中起作用

最佳答案

刚刚关注了这篇文章:Adding a line break to a UITextView

我更新了 JSON feed 以输出新行,例如

testing the data value \nAnother \nmline maybe?

然后在我的代码中运行;

responseDataString = [responseDataString stringByReplacingOccurrencesOfString:@"\\n" withString:@"\n"];

关于objective-c - iOS UITextView 忽略 JSON 响应中的换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13028861/

相关文章:

ios - 如何在iOS中反编译框架文件以获取源代码?

C# 属性 - 需要子属性

ios - 水平 UIPageViewController 内的垂直 UIScrollView 不滚动

objective-c - 为什么我用 "CGMutablePathRef"方法得到相反的掩码

ios - UIWebView 不会在 iOS 7 上出现 "scrollsToTop"?

ios - 使用自动布局在 ScrollView 中添加 uiimageview 会在顶部和底部添加空间

ios - 无法识别应用程序委托(delegate)

jquery - 我可以看到 JSON 对象,但无法访问值

javascript - 从 JSON 文件中删除字符串实例,然后解析它

ios - 在 Objective-C 中将十六进制代码转换为 Unicode