I am trying to import some JSON data into one of my tables in Parse.com. When doing so, I get the following error:
Import encountered the following error: error 111: invalid type for key startDate, expected date, but got string
The data is below:
[
{
"title":"Software Webinar",
"location":"Kingsview Financial",
"host":"Josh Chase",
"startDate":"10/13/2014 12:30",
"EndDate":"10/13/2014 13:30",
"eventType":"TA",
"eventDescrioption":"Informative webinars on utilize and maximize all the features of the TA Trader platform."
}
]
I've tinkered with the date format a bit but to no avail. Just trying to import some data, and have to use JSON data to do so. Thanks for any help.
Formate your date like this:
"startDate": {
"__type": "Date",
"iso": "2014-10-13T12:30:00.000Z"
}
You JSON will look something like this:
[
{
"title":"Software Webinar",
"location":"Kingsview Financial",
"host":"Josh Chase",
"startDate": {
"__type": "Date",
"iso": "2014-10-13T12:30:00.000Z"
},
"EndDate": {
"__type": "Date",
"iso": "2014-10-13T13:30:00.000Z"
},
"eventType":"TA",
"eventDescrioption":"Informative webinars on utilize and maximize all the features of the TA Trader platform."
}
]
Hope this helps.. :)
Related
Sometimes my JSON response is like this
{
"products": [
{
"pId": "3564225",
"name": "Maxi Skirt",
"slug": "maxi-skirt",
"sku": "s-navy",
"priority": 10,
"images": [
]
},
{
"pId": "299328304",
"name": "Necklace Setjewellery",
"slug": "american-diamond-necklace-setjewellery",
"sku": "free-size-purple",
"priority": 10,
"images": [
]
}],
"total": 2
}
And Sometimes it looks like this
{
"products": [
],
"total": 0
}
Swift decoder throws following error when parsing empty array response
"*Swift.DecodingError.Context(codingPath: [], debugDescription:
"The given data was not valid JSON.", underlyingError: Optional(Error Domain=NSCocoaErrorDomain Code=3840
"JSON text did not start with array or object and option to allow fragments not set."
UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}*"
How do I write a swift codable struct to handle multiple response JSON like these above?
PS: I can't change anything from server side.
Both JSON objects are valid and can be decoded into
struct Root: Decodable {
let products : [Product]
let total: Int
}
struct Product: Decodable {
let pId, name, slug, sku : String
let priority : Int
let images : [Image]
}
struct Image: Decodable {
let url : URL
}
As images is empty I just assume that there is an URL. Change it to the real property name(s) and type(s)
Just refer the following link...
https://medium.com/xcblog/painless-json-parsing-with-swift-codable-2c0beaeb21c1
You will get all the stuffs about your issues and more informations in order to decrease further issues and improve your code structure.
I am processing messages. Each message corresponds to a coordinate, and MOST of the coordinates are in a specific JSON form. Problem is, some naughty messages have the wrong format (a different format, where a whole list of coordinates comes in one message).
Ideally, I would like to process both types of message, but the built-in Parse function for JsonProvider seems to succeed even when the incoming data is in the wrong format. How can I know in advance (before attempting to parse) what format my datum is in?
My two data models look something like this:
type ModelA = JsonProvider<"""{
"id": "13222",
"timestamp": 1499329186332.0,
"latitude": 12.125419,
"longitude": 15.054884
}""">
type ModelB = JsonProvider<"""{
"data": {
"positions": [
{
"id": "13223",
"timestamp": 1499329186332.0,
"latitude": 12.125419,
"longitude": 15.054884
},
{
"id": "13223",
"timestamp": 1499329186332.0,
"latitude": 12.125419,
"longitude": 15.054884
}]
}
}""">
I have following REST API response:
"items":
[
{
"empid": "1234",
"name": "Santosh",
"hiredby": "Mark",
"date": "2017-01-31,00:19:41 PST",
},
{
"empid": "5678",
"name": "Kumar",
"hiredby": "Bob",
"date": "2017-01-31,08:30:31 PST"
}
]
My query is : - How do i get empid based on querying name as Kumar.
For example: I need to find "Kumar" name and get his empid. (that is, search by name and get his empid as response) I'm able to get the response and store it in Response object. but, from response object how can i traverse and query to get the required value.
Also,
I tried by retrieving as:
String name = get(REST_ENDPOINT).then().body("items.name",hasItems("Kumar")).extract().path("items.empid").toString();
when i print the response i get collection of the empid like [1234,5678], where as my expectation is to get only 5678.
Do I need to parse via JSONArray and JSONObject and iterate the response?
Please suggest.
You can use something like this
response1.jsonPath().getList("collect { it.credentials.findAll { it.credentialType == 'Ban User Name'}.credentialId }.flatten()")
I have given JSON and cannot parse partial data. It seems dictionary into dictionary:
{
"products": [
{
"id": 6796,
"title": "my title",
"description": "desc",
"code": "12345",
"valueType": "null",
"discounts": [
{
"minPrice": null,
"maxPrice": null,
"value": 20,
"avail": false
}
]
}
]
}
I am using the latest version of RESTKit but I cannot properly parse under discounts.
my RestKit settings are:
responseMapping.addAttributeMappingsFromDictionary([
"id" : "id",
"code" : "code",
"title" : "title",
"valueType" : "valueType",
"description" : "desc",
"discounts.minPrice" : "minPrice",
"discounts.maxPrice" : "maxPrice",
"discounts.value" : "value",
"discounts.avail" : "avail",
])
but all values below discounts always return Nil. What I am doing wrong?
You can't directly map using discounts.XXX because discounts is an array and you have no way to index into that array and extract a single value.
You either need to change the source JSON to compress the values out of the dictionary, or create a custom object that you can map each item in the discounts array to.
Technically you could map the whole discounts array, which would give you an array of dictionaries, that you could then unpack in the setter method, but the array of custom objects is usually a better approach.
I am using Parse and trying to upload a csv file which contains GeoPoints, but when I try to upload them the only options I see is to label it as a string, number, or boolean. Is it possible to import Geopoints or files?
Here's how to do it using JSON import:
{ "results": [
{
"name":"Kfar Saba",
"location": {"__type": "GeoPoint", "latitude": 32.18406, "longitude": 34.91731}
},
{
"name":"Ar'ara BaNegev",
"location": {"__type": "GeoPoint", "latitude": 32.5, "longitude": 35.1}
}
}]
To import GeoPoints, you'll need to use JSON as your file format. See https://parse.com/docs/data#importing for details.