restkit google maps - ios

I'm using RestKit v0.20.0-pre6 for iOS. My input is JSON from a service running on Google App Engine. This is what is being returned from the service:
{
action:"NOP",
payload:null,
timeStamp:new Date(1359427714679),
type:null
}
This is the error I'm getting displayed from RestKit in the output window:
E restkit.network:RKResponseMapperOperation.m:240
Failed to parse response data: Loaded an unprocessable response (200) with content type 'application/json'
It is choking when NSJSONSerialization is called to parse the data. I'm sure it is the line that contains new Date(1359427714679), but I am unsure on how to parse this line. The RestKit documentation mentions writing your own formatter, but I'm unclear on how to do this.
Any insight on how to solve this issue would be much appreciated.

You've got a couple of problems with your JSON here. Firstly, your keys need to be in inverted commas "". Secondly, your web service needs to provide the timestamp as a string.
Try ISO8601 format, e.g.
{
"action" :"NOP",
"payload" : null,
"timeStamp" : "1901-12-13T20:45:52+00:00",
"type": null
}
You can check that your JSON is valid by pasting it into an online validator such as http://www.jslint.com/.

Related

GraphQLResult of JSONObject have JSONString for object whose data type in schema file is JSON

I am using a GraphQL Apollo client for my swift iOS project. During this I have faced some strange result when I got the response from the fetch request of Apollo Client.
My response is look like :
{"getLeadList":{"totalrecord": 8.0,"totalpage": 1.0, "__typename":
"Customdatalist", "data":[{\n \"testTextField_field_id\" : 53},\n
\"textCheckBox\" : \"1\",\n \"phones_field_id\" : 7,\n \"owner\" :
[\n {\n \"srno\" : \"1\",\n \"id\" : \"1\",\n
\"value\" : \"xy#gmail.com\",\n \"name\" : \"Ashish\"\n }\n
],\n \"status_update_date\" : \"1583234662\”}]}}
So while parsing using JSONDecoder().decode it goes into the catch with error detail like The data couldn’t be read because it isn’t in the correct format.
Here you can see that server schema for this query response is as below.
And I have tried with many other queries, and in each response whenever Schema datatype for the key is JSON I faced this issue and not able to solve.
I know there is a solution with convert that String with .utf8 into data but this is not a good solution as some times I am not aware which key have this kind of JSONString. In one JSON response some keys have JSONString and some key have proper JSON formate data. So if any once have faced this please help me to out of this issue.
NOTE: The same query and response is working for Android and React Front end client. I am using Apollo client for communicating with the GraphQL server request and query.

Error uploading GeoJSON to Azure Maps Data Service

I have tried several attempts to upload a GeoJSON FeatureSet to the Azure Map Service REST API.
https://learn.microsoft.com/en-us/rest/api/maps/data/uploadpreview
The JSON I tried came from http://geojson.xyz/ - namely the "populated places simple" file, which you can download here:
https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_50m_populated_places_simple.geojson
1,249 points, 175KB.
On POSTing to /mapData/upload I get a HTTP 200, and 'success' response message.
The response headers includes a location, which when I query I get a 200 back, with this error message in the body.
{
"error": {
"code": "400 BadRequest",
"message":
"Upload request failed.\nYour data has been removed " +
"as we encountered the following problems with it:\n" +
"System.Threading.Tasks.Task`1[System.String[]]"
}
}
Any ideas?
Richard, I wasn't able to repro your issue.
The file is indeed a valid GeoJSON file and I was able to successfully upload the file ne_50m_populated_places_simple.geojson(Downloaded from http://geojson.xyz/) using the Map Data Service Upload API
Please give it another try and feel free to let us know if you still see any issues.
The team is investigating, but they say this is often due to issues with the GeoJSON file. Try pasting your GeoJSON into this site: http://geojson.io/ If you see any red in the side panel, hover over it and it should provide some insights into the issue.

iOS SDK SOAP parsing error : Data at the root level is invalid. Line 1, position 1

I am developing an iPhone app. I have to get data from .NET server. The response is in the following form.
<string xmlns="http://tempuri.org/">
{"success":1,"message":"Data Save Successfully.","returnvalue":"106"}
</string>
I am using NSXMLParser to parse to parse it. I want to get the json string . But the parser is giving error
Server was unable to process request. ---> Data at the root level is invalid. Line 1, position 1.
How can i fix the error.
Thanks in advance
The String in the respons is a JSON, So i think the NSXMLParser don't work with a JSON input. The parsing error is because the syntax of XML is different then from JSON.
This link will help you to read the String JSON response you get.
how to parse json with swift2

How to identify a JSON object using swift and xctest framework?

Using NSJSONSerialization.JSONObjectWithData(..) we can create a JSON object. But is it possible to identify the object type ie. is it a JSON object or not.
I was just trying to check using Swift and XCTestFramework. I tried different ways but no solution still?
Note: After creation of JSON object, I can get the values and can also check the values. XCTest Framework is working fine to test those type of things. But, I stuck to identify the object type.
Anybody has any idea how to identify the JSON object programmatically using Swift and XCTest framework
Update: For example, for a website testing we can do the following:
if let HTTPResponse = response as? NSHTTPURLResponse,
responseURL = HTTPResponse.URL,
MIMEType = HTTPResponse.MIMEType
{
XCTAssertEqual(responseURL.absoluteString, URL.absoluteString, "HTTP response URL should be equal to original URL")
XCTAssertEqual(HTTPResponse.statusCode, 200, "HTTP response status code should be 200")
XCTAssertEqual(MIMEType, "text/html", "HTTP response content type should be text/html")
} else {
XCTFail("Response was not NSHTTPURLResponse")
}
Is something possible like above for JSON?
If you get a valid string within your NSData parameter, but that String is not a valid JSON object, then the parser will throw an error. As from the documentation:
If an error occurs, upon return contains an NSError object that describes the problem.
So check if the object returned is actually an NSError. If you don't get an error, then I would safely assume that the object is indeed a valid JSON object.

Parse JSON string to detect error response

i'm working with a server which response using the JSON format.
when the request contain valid data they respond with a string like this
{"data":{"results":[{"Branch":"ACCT590006"}]}}
but if the parameters of the request are incorrect the response goes like this
{"error":{"errors":[{"domain":"global","reason":"invalid","message":"Invalid
Params"}],"code":98865,"message":"Invalid
param value"}}
So the questions are how i can determine when the response of the server contains a error string using the TJSONObject object and additionally parse the JSON string to show the messages and error codes like this.
Failed reason : invalid
Message : Invalid params
Code: 98865
message : invalid param value.
I've worked a little with JSON, an every time I've parsed from code(delphi 7). But i've searched a little bit, and here you may find the answer of your question:
http://edn.embarcadero.com/print/40882
and with a little adaption this should work.
Best regards,
Radu

Resources