I'm having an issue parsing some of the JSON data being retrieved from Oxford Dictionaries into my application.
I am printing the JSON response into my console which confirms that I am successfully getting the data needed.
Verification that JSON data is being retrieved:
There are two main folders initially when I get the JSON data back. "results", which contains the information I need: the word definition and other information
and "metadata".
JSON format that I am getting back from Oxford Dictionary:
I am able to parse the information contained in the "metadata" folder, and have printed it into the console to confirm.
Verification that I am able to parse and print the metadata:
I however, can't seem to parse any of the data contained in the 'Results' folder, which is what I actually need. The definition, the language, the word ID, et cetera.
What am I doing wrong here??
Example of issue with parsing "results" data:
Another example of faulty attempt to parse 'results':
Plain text copy of my JSON response:
{
"metadata": {
"provider": "Oxford University Press"
},
"results": [
{
"id": "ace",
"language": "en",
"lexicalEntries": [
{
"entries": [
{
"etymologies": [
"Middle English (denoting the ‘one’ on dice): via Old French from Latin as ‘unity, a unit’"
],
"grammaticalFeatures": [
{
"text": "Singular",
"type": "Number"
}
],
"homographNumber": "100",
"senses": [
{
"definitions": [
"a playing card with a single spot on it, ranked as the highest card in its suit in most card games"
],
"domains": [
"Cards"
],
"examples": [
{
"registers": [
"figurative"
],
"text": "life had started dealing him aces again"
},
{
"text": "the ace of diamonds"
}
],
"id": "m_en_gbus0005680.006",
"short_definitions": [
"playing card with single spot on it, ranked as highest card in its suit in most card games"
]
},
{
"definitions": [
"a person who excels at a particular sport or other activity"
],
"domains": [
"Sport"
],
"examples": [
{
"text": "a motorcycle ace"
}
],
"id": "m_en_gbus0005680.010",
"registers": [
"informal"
],
"short_definitions": [
"person who excels at particular sport or other activity"
],
"subsenses": [
{
"definitions": [
"a pilot who has shot down many enemy aircraft"
],
"domains": [
"Air Force"
],
"examples": [
{
"text": "a Battle of Britain ace"
}
],
"id": "m_en_gbus0005680.011",
"short_definitions": [
"pilot who has shot down many enemy aircraft"
]
}
],
"thesaurusLinks": [
{
"entry_id": "ace",
"sense_id": "t_en_gb0000173.001"
}
]
},
{
"definitions": [
"(in tennis and similar games) a service that an opponent is unable to return and thus wins a point"
],
"domains": [
"Tennis"
],
"examples": [
{
"text": "Nadal banged down eight aces in the set"
}
],
"id": "m_en_gbus0005680.013",
"short_definitions": [
"(in tennis and similar games) service that opponent is unable to return and thus wins point"
],
"subsenses": [
{
"definitions": [
"a hole in one"
],
"domains": [
"Golf"
],
"examples": [
{
"text": "his hole in one at the 15th was Senior's second ace as a professional"
}
],
"id": "m_en_gbus0005680.014",
"registers": [
"informal"
],
"short_definitions": [
"hole in one"
]
}
]
}
]
},
{
"etymologies": [
"early 21st century: abbreviation of asexual, with alteration of spelling on the model of ace"
],
"grammaticalFeatures": [
{
"text": "Singular",
"type": "Number"
}
],
"homographNumber": "200",
"senses": [
{
"definitions": [
"a person who has no sexual feelings or desires"
],
"domains": [
"Sex"
],
"examples": [
{
"text": "both asexual, they have managed to connect with other aces offline"
}
],
"id": "m_en_gbus1190638.004",
"short_definitions": [
"asexual person"
]
}
]
}
],
"language": "en",
"lexicalCategory": "Noun",
"pronunciations": [
{
"audioFile": "http://audio.oxforddictionaries.com/en/mp3/ace_1_gb_1_abbr.mp3",
"dialects": [
"British English"
],
"phoneticNotation": "IPA",
"phoneticSpelling": "eɪs"
}
],
"text": "ace"
},
{
"entries": [
{
"grammaticalFeatures": [
{
"text": "Positive",
"type": "Degree"
}
],
"homographNumber": "101",
"senses": [
{
"definitions": [
"very good"
],
"examples": [
{
"text": "Ace! You've done it!"
},
{
"text": "an ace swimmer"
}
],
"id": "m_en_gbus0005680.016",
"registers": [
"informal"
],
"short_definitions": [
"very good"
],
"thesaurusLinks": [
{
"entry_id": "ace",
"sense_id": "t_en_gb0000173.002"
}
]
}
]
},
{
"grammaticalFeatures": [
{
"text": "Positive",
"type": "Degree"
}
],
"homographNumber": "201",
"senses": [
{
"definitions": [
"(of a person) having no sexual feelings or desires; asexual"
],
"domains": [
"Sex"
],
"examples": [
{
"text": "I didn't realize that I was ace for a long time"
}
],
"id": "m_en_gbus1190638.006",
"short_definitions": [
"asexual"
]
}
]
}
],
"language": "en",
"lexicalCategory": "Adjective",
"pronunciations": [
{
"audioFile": "http://audio.oxforddictionaries.com/en/mp3/ace_1_gb_1_abbr.mp3",
"dialects": [
"British English"
],
"phoneticNotation": "IPA",
"phoneticSpelling": "eɪs"
}
],
"text": "ace"
},
{
"entries": [
{
"grammaticalFeatures": [
{
"text": "Transitive",
"type": "Subcategorization"
},
{
"text": "Present",
"type": "Tense"
}
],
"homographNumber": "102",
"senses": [
{
"definitions": [
"(in tennis and similar games) serve an ace against (an opponent)"
],
"domains": [
"Tennis"
],
"examples": [
{
"text": "he can ace opponents with serves of no more than 62 mph"
}
],
"id": "m_en_gbus0005680.020",
"registers": [
"informal"
],
"short_definitions": [
"(in tennis and similar games) serve ace against"
],
"subsenses": [
{
"definitions": [
"score an ace on (a hole) or with (a shot)"
],
"domains": [
"Golf"
],
"examples": [
{
"text": "there was a prize for the first player to ace the hole"
}
],
"id": "m_en_gbus0005680.026",
"short_definitions": [
"score ace on hole or with"
]
}
]
},
{
"definitions": [
"achieve high marks in (a test or exam)"
],
"examples": [
{
"text": "I aced my grammar test"
}
],
"id": "m_en_gbus0005680.028",
"regions": [
"North American"
],
"registers": [
"informal"
],
"short_definitions": [
"achieve high marks in"
],
"subsenses": [
{
"definitions": [
"outdo someone in a competitive situation"
],
"examples": [
{
"text": "the magazine won an award, acing out its rivals"
}
],
"id": "m_en_gbus0005680.029",
"notes": [
{
"text": "\"ace someone out\"",
"type": "wordFormNote"
}
],
"short_definitions": [
"outdo someone in competitive situation"
]
}
]
}
]
}
],
"language": "en",
"lexicalCategory": "Verb",
"pronunciations": [
{
"audioFile": "http://audio.oxforddictionaries.com/en/mp3/ace_1_gb_1_abbr.mp3",
"dialects": [
"British English"
],
"phoneticNotation": "IPA",
"phoneticSpelling": "eɪs"
}
],
"text": "ace"
}
],
"type": "headword",
"word": "ace"
}
]
}
Retrieve results like this:
let results = json["results"][0]["id"]
Or
if let resultObj = json["results"].first {
let id = resultObj["id"]
}
id key is in the dictionary which is at zero index of results array.
Related
I'm attempting to fetch a custom tileset from CARTO using the documentation I found that the way to fetch from the API doc is:
curl --location --request GET 'https://gcp-us-east1.api.carto.com/v3/maps/carto_dw/tileset?name=carto-demo-data.demo_tilesets.nasadem_glo_quadgrid15' --header 'Authorization: Bearer <your access token>'
I made that request on Swift as follows:
{
let urlString = "\(environment.apiBaseURL)/v3/maps/\(environment.connection)/tileset"
return Future<CartoTileJsonResponse, Error> { [weak self] promise in
self?.session
.request(urlString,
method: .get,
parameters: ["name": tileSetName]
)
.validate()
.responseData(completionHandler: { response in
if let error = response.error {
promise(.failure(error))
return
}
guard let data = response.value else {
promise(.failure(response.error ?? NSError(domain: "unknow error", code: 999, userInfo: nil)))
return
}
do {
let cartoTileJsonResponse = try JSONDecoder().decode(CartoTileJsonResponse.self, from: data)
promise(.success(cartoTileJsonResponse))
} catch(let error) {
debugPrint(error)
promise(.failure(error))
}
})
}
}
As the name of the function says this return a new URL which I also make a GET request which finally returns a tilejson as shown:
{
"name": "NiallsFarm_Tileset_1_NDVI",
"tilejson": "3.1.0",
"center": [
-2.637422918924969,
55.96538584577466,
15
],
"description": "",
"maxzoom": 15,
"tilestats": {
"layers": [
{
"layer": "default",
"attributeCount": 2,
"count": 22146,
"geometry": "Polygon",
"attributes": [
{
"type": "String",
"attribute": "fieldName",
"categories": [
{
"category": "South Tempriggs",
"frequency": 7587
},
{
"category": "Kirklands",
"frequency": 6603
},
{
"category": "East Lothian",
"frequency": 4677
},
{
"category": "Crumstanes",
"frequency": 3279
}
]
},
{
"quantiles": {
"3": [
0.5691,
0.658
],
"4": [
0.5328,
0.6307,
0.6627
],
"5": [
0.5112,
0.5942,
0.6515,
0.6658
],
"6": [
0.5004,
0.5699,
0.6307,
0.6578,
0.6675
],
"7": [
0.4899,
0.5509,
0.6055,
0.6464,
0.6604,
0.6689
],
"8": [
0.4824,
0.5344,
0.5841,
0.6303,
0.6545,
0.6627,
0.6697
],
"9": [
0.4768,
0.5212,
0.5705,
0.6123,
0.6436,
0.6576,
0.6646,
0.6705
],
"10": [
0.4708,
0.5112,
0.5574,
0.5937,
0.6303,
0.6516,
0.6596,
0.6657,
0.6712
],
"11": [
0.4674,
0.504,
0.5447,
0.5801,
0.6151,
0.6413,
0.6555,
0.6613,
0.6666,
0.6718
],
"13": [
0.4594,
0.4931,
0.5235,
0.5607,
0.5872,
0.617,
0.6401,
0.6534,
0.6591,
0.6641,
0.6682,
0.6726
],
"14": [
0.4542,
0.4899,
0.5164,
0.5502,
0.5779,
0.6048,
0.6303,
0.6468,
0.6559,
0.6606,
0.665,
0.6688,
0.6731
],
"15": [
0.4514,
0.4866,
0.5112,
0.541,
0.5705,
0.5937,
0.6192,
0.6387,
0.6516,
0.6576,
0.6617,
0.6657,
0.6693,
0.6732
],
"16": [
0.4496,
0.4824,
0.5052,
0.5344,
0.5626,
0.5841,
0.6089,
0.6303,
0.6448,
0.6545,
0.6588,
0.6627,
0.6663,
0.6697,
0.6736
],
"17": [
0.4451,
0.4792,
0.5026,
0.5263,
0.5538,
0.5767,
0.5977,
0.6207,
0.6381,
0.6504,
0.6562,
0.66,
0.6637,
0.6669,
0.6702,
0.6738
],
"18": [
0.4417,
0.476,
0.499,
0.521,
0.547,
0.571,
0.5885,
0.612,
0.6304,
0.6434,
0.6531,
0.6578,
0.6609,
0.6646,
0.6675,
0.6706,
0.674
],
"19": [
0.4394,
0.4729,
0.4952,
0.5154,
0.5407,
0.5643,
0.5821,
0.6018,
0.6226,
0.6372,
0.6483,
0.6551,
0.6587,
0.662,
0.6653,
0.668,
0.6709,
0.6742
],
"20": [
0.4366,
0.4708,
0.4921,
0.5112,
0.5341,
0.5575,
0.576,
0.5941,
0.6135,
0.6304,
0.6423,
0.6521,
0.6564,
0.6596,
0.6627,
0.6658,
0.6684,
0.6712,
0.6744
],
"12We ": [
0.4622,
0.4983,
0.5344,
0.5705,
0.6005,
0.6303,
0.649,
0.6576,
0.6627,
0.6675,
0.6722
]
},
"attribute": "NDVI",
"min": 0.2076,
"avg": 0.5944896234082888,
"type": "Number",
"max": 0.6885,
"sum": "13165.56719999999999590190036258263717172608"
}
]
}
],
"layerCount": 1
},
"tiles": [
"https://gcp-us-east1.api.carto.com/v3/maps/omegacrop-production/tileset/{z}/{x}/{y}?name={NAME}&partition=12_15_16142_16145_10208_10211_3999_1&formatTiles=mvt&cache=1653383237150&access_token={ACCES_TOKEN}"
],
"minzoom": 12,
"attribution": "",
"bounds": [
-2.6481308960412906,
55.9604080548856,
-2.62664091461468,
55.97227003506276
],
"vector_layers": [
{
"field": {
"fieldName": "String",
"NDVI": "Number"
},
"id": "default",
"minzoom": 12,
"geometry_type": "Polygon",
"maxzoom": 15
}
]
}
Which I'm not being able to display on Mapbox Map using either Raster or Vector Layers. Also when trying to do a GET request from the tiles url the tilejson return I'm receiving the following error:
{
"error": "invalid zoom value, must be an integer number greater than or equal to 0",
"status": 400,
"message": "invalid zoom value, must be an integer number greater than or equal to 0",
"z": null,
"x": null,
"y": null
}
If anyone have experienced this or may know what I may be doing wrong it would be highly appreciated.
I'm new to developing IVR with twilio studio so I started with the basic template and even that's not working.
This is the log:
LOG
Split Based On...
DETAIL
Input evaluated to 'Sales.' from '{{widgets.gather_input.SpeechResult}}'
Transitioning to 'say_play_1' because 'Sales.' did not match any expression
The split is set to "Equal to" sales which then connects the call to a number. It's obviously recognizing the correct speech input but still not working. Any ideas?
{
"description": "IVR",
"states": [
{
"name": "Trigger",
"type": "trigger",
"transitions": [
{
"event": "incomingMessage"
},
{
"next": "gather_input",
"event": "incomingCall"
},
{
"event": "incomingRequest"
}
],
"properties": {
"offset": {
"x": 250,
"y": 50
}
}
},
{
"name": "gather_input",
"type": "gather-input-on-call",
"transitions": [
{
"next": "split_key_press",
"event": "keypress"
},
{
"next": "split_speech_result",
"event": "speech"
},
{
"event": "timeout"
}
],
"properties": {
"voice": "alice",
"speech_timeout": "auto",
"offset": {
"x": 290,
"y": 250
},
"loop": 1,
"hints": "support,sales",
"finish_on_key": "",
"say": "Hello, how can we direct your call? Press 1 for sales, or say sales. To reach support, press 2 or say support.",
"language": "en",
"stop_gather": false,
"gather_language": "en-US",
"profanity_filter": "false",
"timeout": 5
}
},
{
"name": "split_key_press",
"type": "split-based-on",
"transitions": [
{
"event": "noMatch"
},
{
"next": "connect_call_to_sales",
"event": "match",
"conditions": [
{
"friendly_name": "1",
"arguments": [
"{{widgets.gather_input.Digits}}"
],
"type": "equal_to",
"value": "1"
}
]
},
{
"next": "connect_call_to_support",
"event": "match",
"conditions": [
{
"friendly_name": "2",
"arguments": [
"{{widgets.gather_input.Digits}}"
],
"type": "equal_to",
"value": "2"
}
]
}
],
"properties": {
"input": "{{widgets.gather_input.Digits}}",
"offset": {
"x": 100,
"y": 510
}
}
},
{
"name": "split_speech_result",
"type": "split-based-on",
"transitions": [
{
"next": "say_play_1",
"event": "noMatch"
},
{
"next": "connect_call_to_sales",
"event": "match",
"conditions": [
{
"friendly_name": "sales",
"arguments": [
"{{widgets.gather_input.SpeechResult}}"
],
"type": "equal_to",
"value": "sales"
}
]
},
{
"next": "connect_call_to_support",
"event": "match",
"conditions": [
{
"friendly_name": "support",
"arguments": [
"{{widgets.gather_input.SpeechResult}}"
],
"type": "equal_to",
"value": "support"
}
]
}
],
"properties": {
"input": "{{widgets.gather_input.SpeechResult}}",
"offset": {
"x": 510,
"y": 510
}
}
},
{
"name": "connect_call_to_sales",
"type": "connect-call-to",
"transitions": [
{
"event": "callCompleted"
}
],
"properties": {
"offset": {
"x": 100,
"y": 750
},
"caller_id": "{{contact.channel.address}}",
"noun": "number",
"to": "12222222",
"timeout": 30
}
},
{
"name": "connect_call_to_support",
"type": "connect-call-to",
"transitions": [
{
"event": "callCompleted"
}
],
"properties": {
"offset": {
"x": 520,
"y": 750
},
"caller_id": "{{contact.channel.address}}",
"noun": "number",
"to": "12222222",
"timeout": 30
}
},
{
"name": "say_play_1",
"type": "say-play",
"transitions": [
{
"next": "gather_input",
"event": "audioComplete"
}
],
"properties": {
"offset": {
"x": 710,
"y": 200
},
"loop": 1,
"say": "not valid choice."
}
}
],
"initial_state": "Trigger",
"flags": {
"allow_concurrent_calls": true
}
}
Twilio developer evangelist here.
That is weird behaviour, mainly because the log says "evaluated to 'Sales.'". Split widgets conditions are not case-sensitive and should trim leading and following white-space. For some reason this appears to have a capital "S" and a full-stop.
I would suggest a couple of things. Firstly, raise a ticket with Twilio support to look into why the condition didn't match correctly.
Then, try some of the other conditions. When I generate a new IVR template in Studio, the conditions use "Matches any of" instead of "Equal to". You might also try "Contains".
So, experiment with the ways you can match the operators, but get support involved to drill down into why it didn't work in the first place.
The period is needed after the word for some reason...I just put both, for example:
"1, 1., Uno, Uno., Una, Una., Uno, Uno., Español, Español., Español, Español., Español, Español."
I always receive 500 Internal Service Error
POST: https://atlas.microsoft.com/mapData/upload?subscription-key=&api-version=1.0&dataFormat=geojson
Sample data:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-122.13393688201903,
47.63829579223815
],
[
-122.13389128446579,
47.63782047131512
],
[
-122.13240802288054,
47.63783312249837
],
[
-122.13238388299942,
47.63829037035086
],
[
-122.13393688201903,
47.63829579223815
]
]
]
},
"properties": {
"geometryId": "1"
}
},
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-122.13374376296996,
47.63784758098976
],
[
-122.13277012109755,
47.63784577367854
],
[
-122.13314831256866,
47.6382813338708
],
[
-122.1334782242775,
47.63827591198201
],
[
-122.13374376296996,
47.63784758098976
]
]
]
},
"properties": {
"geometryId": "2",
"validityTime": {
"expiredTime": "2019-01-15T00:00:00",
"validityPeriod": [
{
"startTime": "2019-01-08T01:00:00",
"endTime": "2019-01-08T17:00:00",
"recurrenceType": "Daily",
"recurrenceFrequency": 1,
"businessDayOnly": true
}
]
}
}
}
]
}
Need help
I have a timeseries data which I am trying to display with Highstocks:
Here is the data:
{
"title": {
"text": "My Graph"
},
"series": [
[
{
"name": "Future Index Longs",
"data": [
[
"2019-02-05",
104516
],
[
"2019-02-06",
127260
],
[
"2019-02-07",
156291
],
[
"2019-02-08",
167567
]
]
}
],
[
{
"name": "Future Index Longs",
"data": [
[
"2019-02-05",
21
],
[
"2019-02-06",
0
],
[
"2019-02-07",
1263
],
[
"2019-02-08",
12
]
]
}
],
[
{
"name": "Future Index Longs",
"data": [
[
"2019-02-05",
33873
],
[
"2019-02-06",
61093
],
[
"2019-02-07",
43125
],
[
"2019-02-08",
41928
]
]
}
],
[
{
"name": "Future Index Longs",
"data": [
[
"2019-02-05",
47542
],
[
"2019-02-06",
55084
],
[
"2019-02-07",
75256
],
[
"2019-02-08",
77786
]
]
}
],
[
{
"name": "Future Index Longs",
"data": [
[
"2019-02-05",
185952
],
[
"2019-02-06",
243437
],
[
"2019-02-07",
275935
],
[
"2019-02-08",
287293
]
]
}
]
]
}
The graph is empty and no data is displayed. What am I doing wrong?
Sorry to add this filler here but I am required to add more text to post this question and since this is a pretty simple question, I don't have much to add.
You have the wrong format on your series, it should be an array of objects.
Like this: series: [{ ... }, { ... }]
Check this fiddle: https://jsfiddle.net/wg1vnyzp/1/
To have a chart with datetime axes in Highcharts you have to pass the X value as the timestamp in milliseconds since 1970.
Highstock example:
https://jsfiddle.net/BlackLabel/f0rsz6cd/1/
Note that in Highcharts you have to define xAxis.type as datetime like that:
xAxis: {
type: 'datetime'
}
Highcharts demo:
https://jsfiddle.net/BlackLabel/kas2oywp/
API reference:
https://api.highcharts.com/highcharts/series.line.data.x
https://api.highcharts.com/highcharts/xAxis.type
I Post one Json with RestAssured and After I need to verify that all fields are stored in the database with the correct values.My Json is :
{
"id": "1",
"name": "name1",
"description": "description1",
"source": "source1",
"target": "target1",
"domain": "PM",
"transformation_rules": [
{
"name": "name2",
"filters": [
{
"object": "object1",
"pattern": "pattern1"
}
],
"operations": [
{
"pattern": "pattern2",
"replacement": "replacement1"
}
]
},
{
"name": "name3",
"filters": [
{
"object": "object2",
"pattern": "pattern2"
}
],
"operations": [
{
"pattern": "pattern3",
"replacement": "replacement2"
},
{
"pattern": "pattern3",
"replacement": "replacement3"
},
{
"pattern": "pattern4",
"replacement": "replacement4"
}
]
}
],
"conflict_policy": "ACCEPT_SOURCE"
}
So, I have :
responseGet = RestAssured.given().contentType(ContentType.JSON).when().get(urlApi + "/" + id);
My first verification is :
responseGet.then().body("$[0]['id']", equalTo("1"));
to verify that the field "id" equals to 1 it doesn't execute well and I change to :
responseGet.then().body("$.id", equalTo("1"));
and the same result ---> fails
Please, can you give me your suggestions for testing all the Json ?
Just for information, I try to apply : https://github.com/json-path/JsonPath.
Thank you very much in Advance,
Best Regards,
You can directly use jsonPath() for checking this:
For example:
responseGet.body().jsonPath().getString("id").equals("1");
For reading JsonPath