0

At the server, I have a string of text that is concatenated together and has \n added to create line breaks. This is done in VB.net as a string object.

This string is that added to a dictionary which is then available as a JSON webservice.

On my iOS app, I am reading the JSON and parsing it, saving the contents to core data.

when I display my text in a UITextView the string "hello\nthere" is shown exactly like that with no line breaks and the \n visible.

what have I done wrong?

I have also tried \r instead.

should I be making a string in the vb.net part like this "hello\nthere" - is that valid, or should I be using "hello" & vbcrlf & "there" and letting the JSON parser convert the line break to \n (if it does this)

or is the problem in the iOS side?

Prasad Devadiga
  • 2,573
  • 20
  • 43
James Dawson
  • 948
  • 10
  • 12
  • Whether `\n` means a line break or just the two characters `\` and `n` depends on context. Any JSON encoding mechanism should be able to mask line breaks correctly by itself. – CBroe May 31 '13 at 09:03
  • 4
    Have you tried setting a breakpoint inside the iOS-app and checking the string? It might have been escaped somewhere, resulting in "\\n" (probably somewhere around core-data). See http://stackoverflow.com/questions/3697253/adding-a-line-break-to-a-uitextview – patric.schenke May 31 '13 at 09:51
  • sorry for not replying i was on holiday then busy. i will try these suggestions now – James Dawson Jun 25 '13 at 13:52
  • thanks patric - it had indeed escaped it making \\n. using entity.fielname = [thetext stringByReplacingOccurrencesOfString: @"\\n" withString: @"\n"]; to save to core data (obvioslu not the real entity, field or variable names btw) has done the trick. – James Dawson Jun 25 '13 at 14:24

1 Answers1

0

can't see how else to mark this as complete - but please see the comment from – patric.schenke May 31 at 9:51

he was indeed corerct - the text had escaped to \n so replacing this with \n and saving that to core data has solved the issue.

James Dawson
  • 948
  • 10
  • 12