2

I'm developing an ios app, however when I try to get a server response by using this:

 if let jsonResult = try NSJSONSerialization.JSONObjectWithData(data!, options: []) as? NSDictionary

I get an error from the server that says:

The data couldn't be read because it's in an incorrect format.

Because my server has the problematic line of code:

{"tripReport":[{"duration":-,"distance":0.0,"reportText1":" " ,"reportText2":"-" ,"totalDistance":0.0,"message1":" ","message2":" ","dateTime2":" ","dateTime1":" "}],"size":0}

I want to get the server response before this line instead, like:{"movementReport":[{"message":"7.88 KM SE of Police Line Constibilary, Faisalabad - Jaranwala Road, FAISALABAD, PUNJAB, PK","reportText":"POSITION","speed":53.0,"dateTime":"2016-Jan-20 11:36 AM","route":null,"longitude":73.270053,"latitude":31.37281}
by using split func or any thing else.. can i brake my response into two strings?

Magisch
  • 7,312
  • 9
  • 36
  • 52
zeeshan nazakat
  • 151
  • 3
  • 18
  • First of all, there's no way for us to know which format is accepted by your server, therefore we are unable to compare with the text you provided. Secondly, the provided text is not a valid JSON, the duration value can't be parsed from it. – A-Live Jan 20 '16 at 08:47
  • yes i know this invalid.. thats why i want to ignore this line.. like split("\\{\"tripReport\") ?? – zeeshan nazakat Jan 20 '16 at 09:12
  • Ah ok, what is the problem then, do you need help splitting a string ? I'm sure there's a lot of answered questions for that, [for example](http://stackoverflow.com/questions/25678373/swift-split-a-string-into-an-array) – A-Live Jan 20 '16 at 09:24
  • I can split string but there is a problem the object(server response) that I want to split it is NSDictionary form when I try to split it says : – zeeshan nazakat Jan 20 '16 at 09:47
  • can not convert into string NSDictionary – zeeshan nazakat Jan 20 '16 at 09:47
  • /Users/Irfan/Documents/My ISO APPS/VITS/VITS/MovementRep.swift:71:57: Cannot convert value of type 'String' to expected argument type '_Element' (aka 'Character') – zeeshan nazakat Jan 20 '16 at 09:48

0 Answers0