0
  • Here is a field value returned by web service in JSON ^\+?\d+(-\d+)*$ but when i get it, it becomes ^+?d+(-d+)*$.
  • But i need the original one from JSON. How to get the same from objective C.

For example : If i use NSString *string=@"^\+?\d+(-\d+)*$";, It shows ^+?d+(-d+)*$ in NSLog. How to prevent this?

Thanks

Tunvir Rahman Tusher
  • 6,421
  • 2
  • 37
  • 32
  • It's not being encoded/decoded properly then. Which side is at fault is unclear without more information. – trojanfoe Oct 31 '14 at 09:29
  • Its actually from web service...i actually want to get the response as it is..possible? – Tunvir Rahman Tusher Oct 31 '14 at 09:30
  • The JSON encoder will consider escape characters in the input string and further escape *them* in order to preserve the regular expression. If that is not happening then the encoder is broken and there is nothing you can do on the client side. That is, if you are correctly decoding them. However you don't show the code, so who knows? – trojanfoe Oct 31 '14 at 09:37
  • I disagree with the example you provide; that is not true. – trojanfoe Oct 31 '14 at 10:03
  • The question is edited...please check now. – Tunvir Rahman Tusher Nov 01 '14 at 06:11

1 Answers1

1

You should add the escape character in the response. Get the response in below way from web service. Tell your web service developer to format the response in below way. Character '\' can be received via adding escape sequence.

 ^\\+?\\d+(-\\d+)*$
Apurv
  • 17,116
  • 8
  • 51
  • 67