Restkit mapping 0.2 - ios

How to map a json like this in Restkit 2.0.I can't find a tutorial and all tutorials there is for previous versions.I know how it is done in 0.10.0 but dont have an idea how to do this array and nested arrays in 0.20.0
{
"days" : [
{
"day" : 1,
"id" : 1,
"set1" : [
{
"exercise_id" : 1,
"exerciseunits" : [
{
"count" : 3,
"id" : 1,
"weight" : 60
}
],
"id" : 1,
"name" : null,
"subbodypart_id" : 1,
"subbodypartname" : "Chest"
}
]
}
],
"description" : "desc",
"id" : 1,
"name" : "asdfg"
}

Use the updated documentation in the wiki about object mapping. More than that you can download the current RestKit master with examples (e.g. Twitter Core Data) where nested objects are used as well.

Related

Extracting a specific part from JSON

Hello I am trying to extract only the id value from a JSON. However if I
print(response!["id"])
result = "not created" is outputted. reponse is already in JSON format.
Is there something that I am doing wrong?
Update 1
[
{
"user" : {
"last_name" : "test",
"email" : "test#test.com",
},
"id" : 902,
"scale" : 7,
"created_at" : "2018-02-24 06:45:33",
},
{
"user" : {
"last_name" : "test",
"email" : "test#test.com",
},
"id" : 903,
"scale" : 7,
"created_at" : "2018-02-24 06:45:33",
},
{
"user" : {
"last_name" : "test",
"email" : "test#test.com",
},
"id" : 904,
"scale" : 7,
"created_at" : "2018-02-24 06:45:33",
},
]
The best way to access the id of any object from the array of response will be:
let id = response[index]["id"]
// Here index is the index of the object you want to access.
I am assuming you want to extract ids from this JSON array. You can do this using
response.map({ $0["id"]})
Which will give you another array containing only ids

Spring Data Neo4j corrupted json

I'm using neo4j with spring data, when I store an object with inside a relation I get as a result of the findAll a corrupted json. I never get this error when I query the objects one at time.
Even more strange the first one in the list is correct but the second has this error. The error is at the edge field. Any idea?
[{
"uuid" : "e5c90af5-6259-4ddf-ae1f-c0cff5a41296",
"name" : "test",
"createdBy" : {
"uuid" : "319535cc-288f-4a23-bc02-a3b01bf6e93f",
"createdAt" : "2017-03-10T02:06:55.925+0000",
"user" : {
"uuid" : "9e91032e-a54d-4297-8a6a-1506589b7529",
},
"edge" : { "id" : 6514
},
"graphId" : 664
}
},
{
"uuid" : "e5c90af5-6259-4ddf-ae1f-c0cff5a41296",
"name" : "test",
"createdBy" : {
"uuid" : "319535cc-288f-4a23-bc02-a3b01bf6e93f",
"createdAt" : "2017-03-10T02:06:55.925+0000",
"user" : {
"uuid" : "9e91032e-a54d-4297-8a6a-1506589b7529",
},
"edge" : { : 6514
},
"graphId" : 664
}
}]

Updating an array field that contains hashes in mongoid

I have a document in XYZ collection as follows.
"_id" : ObjectId("55311e4487216d7063040000"),
"colours" : [
{
"value" : 1,
"colour" : "red"
},
{
"value" : 2,
"colour" : "green"
}
]
I need to update the name of the colour which value is 1. What query should I write?
I am using rails 4.1.2, mongoid 4.0.0.
Please help.
For example you want to change it to "yellow" :
XYZ.where(_id: "55311e4487216d7063040000").elem_match(colours: { value: 1 }).update("$set" => {"colours.$.colour" => "yellow"})

cypher PROFILE via neo4j REST API

Can anyone tell me how to run a PROFILE'd query using teh neo4j REST API such as
PROFILE MATCH (n:LABEL) return n;
When I run this either in Java using the RestCypherQueryEngine or the even using a raw HTTP post directly I get
message: "Invalid input 'P': expected SingleStatement (line 1, column 1) "PROFILE MATCH (n:LABEL) return n;" ^"
exception: "SyntaxException"
I though I had read somewhere that this is possible not only through the server console
The old cypher endpoint (i.e /db/data/cypher) had a ?profile=true query parameter that adds profiling information to the result.
e.g.
curl -H accept:application/json -H content-type:application/json
-d'{"query":"MATCH (n) RETURN count(*)","params":{}}'
http://localhost:7474/d/data/cypher?profile=true
{
"columns" : [ "count(*)" ],
"data" : [ [ 0 ] ],
"plan" : {
"args" : {
"returnItemNames" : [ "count(*)" ],
"_rows" : 1,
"_db_hits" : 0,
"symKeys" : [ " INTERNAL_AGGREGATE75acebd9-82d7-4a65-921c-2049c4bde4e7" ]
},
"dbHits" : 0,
"name" : "ColumnFilter",
"children" : [ {
"args" : {
"keys" : [ ],
"_rows" : 1,
"aggregates" : [ "( INTERNAL_AGGREGATE75acebd9-82d7-4a65-921c-2049c4bde4e7,CountStar())" ],
"_db_hits" : 0
},
"dbHits" : 0,
"name" : "EagerAggregation",
"children" : [ {
"args" : {
"_rows" : 0,
"_db_hits" : 0,
"identifier" : "n"
},
"dbHits" : 0,
"name" : "AllNodes",
"children" : [ ],
"rows" : 0
} ],
"rows" : 1
} ],
"rows" : 1
}
}

ElasticSearch geo_bounding_box coordinate format

I was following the ElasticSearch guide online to represent coordinates as "lat, lng" but it doesnt seem to be working until I flip everything around to "lng, lat". I even have to flip around top_left and bottom_right in order for the query to work.
Is anyone experiencing the same problem? Clearly this is not how the documentation says to use it, but it's only working when I format it this way.
Rails format
def self.search(params)
tire.search( page: params[:page], per_page: 2 ) do
query { all }
filter :geo_bounding_box, location: { top_left: " -121.88596979687497, 37.33588487375733", bottom_right: " -122.43528620312497, 37.553946238118264" }
end
end
CURL format
curl -X GET "http://localhost:9200/articles/article/_search?page=&per_page=2&size=2&pretty=true" -d '{"query":{"match_all":{}},"facets":{"condition":{"terms":{"field":"condition","size":10,"all_terms":false}}},"filter":{"geo_bounding_box":{"location":{"top_left":" -121.88596979687497, 37.33588487375733","bottom_right":" -122.43528620312497, 37.553946238118264"}}},"size":2}'
Console response
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 169,
"max_score" : 1.0,
"hits" : [ {
"_index" : "articles",
"_type" : "article",
"_id" : "4f72bc7d0bdb820f02000002",
"_score" : 1.0, "_source" : {"content":"words here!","location":[37.444995,-122.160628],"name":"harro"}
}, {
"_index" : "articles",
"_type" : "article",
"_id" : "4fdf0cf20bdb82336c000002",
"_score" : 1.0, "_source" : {"content":"Run of the mill","location":[37.33588487375733,-121.88596979687497],"name":"Billy Bob"}
} ]
},
"facets" : {
"condition" : {
"_type" : "terms",
"missing" : 5597,
"total" : 0,
"other" : 0,
"terms" : [ ]
}
}
When geo point is specified as a string, it should be in "lat,lon" format. When it is specified as an array, it should be in [lon, lat] format.

Resources