Related
So I can call the variable "teams" and see the data fine but I can't get the values from it in my {#each} block. I know its not part of the "fixtures" variable I'm iterating through and tbh that's probably the issue.
Does anyone know how I can get the actual values within "teams" instead of getting 'undefined' or a better way of fetching multiple arrays within themselves? (ill put the example at the bottom)
my +page.svelte
<script>
export let data;
const { fixtures } = data;
const teams = fixtures.flatMap(fixtures => fixtures.participants)
console.log(teams)
</script>
<div class="flex flex-col absolute top-[0] right-0 w-[85vw] p-6">
<div class="">
{#each fixtures as fixture}
<p>{fixture.name}</p>
<div class="">{fixture.home_score}{fixture.away_score}</div>
<p>{teams.short_code}</p>
{/each}
</div>
</div>
+page.server.js
export const load = async () => {
const fetchList= async () => {
const url = `https://api.sportmonks.com/v3/football/schedules/seasons/19734?api_token=${process.env.API_KEY}`;
const res = await fetch(url);
const data = await res.json()
return data.data.flatMap(data => data.rounds.map(rounds => rounds.fixtures)).flat()
}
return {
fixtures: fetchList(),
}
}
The API
{
"data": [
{
"id": 77457864,
"sport_id": 1,
"league_id": 8,
"season_id": 19734,
"type_id": 223,
"name": "Regular Season",
"sort_order": 1,
"finished": false,
"is_current": true,
"starting_at": "2022-08-05",
"ending_at": "2023-05-28",
"rounds": [
{
"id": 274668,
"sport_id": 1,
"league_id": 8,
"season_id": 19734,
"stage_id": 77457864,
"name": "1",
"finished": true,
"is_current": false,
"starting_at": "2022-08-05",
"ending_at": "2022-08-07",
"fixtures": [
{
"id": 18535049,
"sport_id": 1,
"league_id": 8,
"season_id": 19734,
"stage_id": 77457864,
"group_id": null,
"aggregate_id": null,
"round_id": 274668,
"state_id": 5,
"venue_id": 206,
"name": "Manchester United vs Brighton & Hove Albion",
"home_score": 1,
"away_score": 2,
"starting_at": "2022-08-07 13:00:00",
"result_info": "Brighton & Hove Albion won after full-time.",
"leg": "1/1",
"details": null,
"length": 90,
"placeholder": false,
"last_processed_at": "2022-12-05 09:15:37",
"starting_at_timestamp": 1659877200,
"participants": [
{
"id": 14,
"sport_id": 1,
"country_id": 462,
"venue_id": 206,
"gender": "male",
"name": "Manchester United",
"short_code": "MUN",
"image_path": "https://cdn.sportmonks.com/images/soccer/teams/14/14.png",
"founded": 1878,
"type": "domestic",
"placeholder": false,
"last_played_at": "2022-12-10 17:00:00",
"meta": {
"location": "home"
}
},
{
"id": 78,
"sport_id": 1,
"country_id": 462,
"venue_id": 480,
"gender": "male",
"name": "Brighton & Hove Albion",
"short_code": "BRH",
"image_path": "https://cdn.sportmonks.com/images/soccer/teams/14/78.png",
"founded": 1901,
"type": "domestic",
"placeholder": false,
"last_played_at": "2022-12-08 13:00:00",
"meta": {
"location": "away"
}
}
]
},
There's a "dirty" way to do it with {#key}
I have a json file.
[
{
"line": 1,
"elements": [
{
"start_timestamp": "2022-10-17T20:07:41.706Z",
"steps": [
{
"result": {
"duration": 12216552000,
"status": "passed"
},
"line": 5,
"name": "m0e",
"match": {
"location": "seleniumgluecode.book.user_is_on_homepagee()"
},
"keyword": "Given "
},
{
"result": {
"duration": 2074982200,
"status": "passed"
},
"line": 6,
"name": "m1e1",
"match": {
"location": "seleniumgluecode.book.user_enters_Usernamee()"
},
"keyword": "When "
}
],
"tags": [
{
"name": "#Smokee"
}
]
},
{
"start_timestamp": "2022-10-17T20:08:12.284Z",
"steps": [
{
"result": {
"duration": 12090584100,
"status": "passed"
},
"line": 12,
"name": "m0e2",
"match": {
"location": "seleniumgluecode.book2.user_is_on_homepageee()"
},
"keyword": "Given "
}
],
"tags": [
{
"name": "#Smokee"
}
]
}
],
"name": "Login Featuree",
"description": " Verify if user is able to Login in to the sitee",
"id": "login-featuree",
"keyword": "Feature",
"uri": "file:src/test/java/features/tribe/squad1/kitab.feature",
"tags": []
},
{
"line": 1,
"elements": [
{
"start_timestamp": "2022-10-17T20:08:34.480Z",
"steps": [
{
"result": {
"duration": 11366098500,
"status": "passed"
},
"line": 5,
"name": "m0e",
"match": {
"location": "seleniumgluecode.book.user_is_on_homepagee()"
},
"keyword": "Given "
}
],
"tags": [
{
"name": "#Smokee"
}
]
}
],
"name": "Login Featureefghfgh",
"description": " Verify if user is able to Login in to the sitee",
"id": "login-featureefghfgh",
"keyword": "Feature",
"uri": "file:src/test/java/features/tribe1/squad2/kitab2.feature",
"tags": []
},
{
"line": 19,
"elements": [
{
"start_timestamp": "2022-10-17T20:09:40.836Z",
"steps": [
{
"result": {
"duration": 12761711100,
"status": "passed"
},
"line": 23,
"name": "m0e",
"match": {
"location": "seleniumgluecode.book.user_is_on_homepagee()"
},
"keyword": "Given "
}
],
"tags": [
{
"name": "#Smokee"
}
]
}
],
"name": "X Feature",
"description": " Verify if user is able to Login in to the sitee",
"id": "login-featuree",
"keyword": "Feature",
"uri": "file:src/test/java/features/tribe2/test.feature",
"tags": []
}
]
I am getting url addresses in this array
document.addEventListener("DOMContentLoaded", () => {
var i = report.length;
var array = [];
for(x = 0; x < i; x++){
array.push(report[x].uri.split("/"));
}
console.log(array2);
});
This return me :
0:
(7) ['file:src', 'test', 'java', 'features', 'tribe1', 'squad1', 'kitab.feature']
1:
(7) ['file:src', 'test', 'java', 'features', 'tribe1', 'squad2', 'kitab2.feature']
2:
(6) ['file:src', 'test', 'java', 'features', 'tribe2, kitab3.feature']
I don't need file:src, test, java, features. Deleting them in 3 arrays and getting a unique array like this:
0:
(3) ['tribe1', 'squad1', 'kitab.feature']
1:
(3) ['tribe1', 'squad2', 'kitab2.feature']
2:
(2) ['tribe2, kitab3.feature']
Finally, if there are 2 elements before the .feature, I need to create a new array by considering 1 as squad and 2 as tribe. Like this:
Diagram
[tribe1
squad1
elem
1
2
name
url
squad2
elem
1
2
name
url
tribe2
elem
1
2
name
url
]
How can I do that?. Thank you.
You should try destructing the array. An example is shown below:
[a,b,c,d, ...rest] = ['file:src', 'test', 'java', 'features', 'tribe1', 'squad1', 'kitab.feature']
console.log(rest);
You can transform or create a new array based on input array with this simple logic with the help of Array.map() along with String.split() and Array.splice() method.
Live Demo :
const arr = [
{
"line": 1,
"uri": "file:src/test/java/features/tribe/squad1/kitab.feature"
},
{
"line": 1,
"uri": "file:src/test/java/features/tribe1/squad2/kitab2.feature"
},
{
"line": 19,
"uri": "file:src/test/java/features/tribe2/test.feature"
}
];
const res = arr.map(({ uri}) => uri.split('/').splice(4));
console.log(res);
I'm new to Actions on Google and Node.js, but this seems like it should be straightforward and I'm not sure why it's not working. I just want to send a GET request within the code that handles a specific intent. At the moment, I'm not even looking for a return value; I just want to fire off the request. I'm using the Blaze tier of Firebase, which is supposed to allow outgoing HTTPS requests. Indeed, I can get the Action to play an audio file from my server in SSML. But when I put in a GET request to a PHP page that increments a value in a database, it isn't being executed successfully.
My code is taken directly from Google's CodeLabs tutorials for Actions. Below is the only function I'm modifying. This code runs, but the GET request is never received.
// Handle the Dialogflow intent named 'favorite color'.
// The intent collects a parameter named 'color'.
app.intent('favorite color', (conv, {color}) => {
const luckyNumber = color.length;
const audioSound = 'https://my.server.tld/path/to/sound.mp3';
// These two lines don't seem to do what I'm expecting them to.
var https = require("https");
https.get('https://my.server.tld/path/to/file.php?value=1');
conv.ask(`<speak>Your lucky number is ${luckyNumber}.` +
`<audio src="${audioSound}"></audio>` +
`Would you like to hear some fake colors?</speak>`);
});
There's nothing that jumps out at me as unusual in the Firebase logs (excerpted below). There doesn't seem to be any mention of the GET call I'm trying to make.
4:19:11.631 PM dialogflowFirebaseFulfillment Function execution took 569 ms, finished with status code: 200
4:19:11.543 PM dialogflowFirebaseFulfillment Response { "status": 200, "headers": { "content-type": "application/json; charset=utf-8" }, "body": { "payload": { "google": { "expectUserResponse": true, "richResponse": { "items": [ { "simpleResponse": { "textToSpeech": "<speak>Three. Your lucky number is 4.<audio src=\"https://actions.google.com/sounds/v1/cartoon/clang_and_wobble.ogg\"></audio>Would you like to hear some fake colors?</speak>" } } ] }, "userStorage": "{\"data\":{}}" } }, "outputContexts": [ { "name": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh/contexts/_actions_on_google", "lifespanCount": 99, "parameters": { "data": "{}" } } ] } }
4:19:11.434 PM dialogflowFirebaseFulfillment Conversation { "responses": [], "expectUserResponse": true, "digested": false, "noInputs": [], "_responded": false, "request": "[Excluded]", "headers": "[Excluded]", "sandbox": true, "input": { "raw": "blue", "type": "KEYBOARD" }, "surface": { "capabilities": { "list": [ { "name": "actions.capability.WEB_BROWSER" }, { "name": "actions.capability.MEDIA_RESPONSE_AUDIO" }, { "name": "actions.capability.SCREEN_OUTPUT" }, { "name": "actions.capability.AUDIO_OUTPUT" } ] } }, "available": { "surfaces": { "list": [ { "capabilities": { "list": [ { "name": "actions.capability.WEB_BROWSER" }, { "name": "actions.capability.SCREEN_OUTPUT" }, { "name": "actions.capability.AUDIO_OUTPUT" } ] } } ], "capabilities": { "surfaces": [ { "capabilities": { "list": [ { "name": "actions.capability.WEB_BROWSER" }, { "name": "actions.capability.SCREEN_OUTPUT" }, { "name": "actions.capability.AUDIO_OUTPUT" } ] } } ] } } }, "user": { "raw": { "userStorage": "{\"data\":{}}", "lastSeen": "2018-09-26T23:19:06Z", "locale": "en-US", "userId": "ABwppHHp5yhn_VrB_SIGG93tCzMx9o0A_W9bIDlbCClkqcV85LrVbJ42vLQ7hWXfe3UOd7pASDIm6v_q" }, "storage": {}, "_id": "ABwppHHp5yhn_VrB_SIGG93tCzMx9o0A_W9bIDlbCClkqcV85LrVbJ42vLQ7hWXfe3UOd7pASDIm6v_q", "locale": "en-US", "permissions": [], "last": { "seen": "2018-09-26T23:19:06.000Z" }, "name": {}, "entitlements": [], "access": {}, "profile": {} }, "arguments": { "parsed": { "input": { "text": "blue" }, "list": [ "blue" ] }, "status": { "input": {}, "list": [ null ] }, "raw": { "list": [ { "rawText": "blue", "textValue": "blue", "name": "text" } ], "input": { "text": { "rawText": "blue", "textValue": "blue", "name": "text" } } } }, "device": {}, "id": "ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh", "type": "ACTIVE", "screen": true, "body": "[Excluded]", "version": 2, "action": "", "intent": "favorite color", "parameters": { "color": "blue" }, "contexts": { "_session": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh", "input": { "actions_capability_screen_output": { "name": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh/contexts/actions_capability_screen_output", "parameters": { "color": "blue", "color.original": "blue" } }, "actions_capability_audio_output": { "name": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh/contexts/actions_capability_audio_output", "parameters": { "color": "blue", "color.original": "blue" } }, "google_assistant_input_type_keyboard": { "name": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh/contexts/google_assistant_input_type_keyboard", "parameters": { "color": "blue", "color.original": "blue" } }, "actions_capability_web_browser": { "name": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh/contexts/actions_capability_web_browser", "parameters": { "color": "blue", "color.original": "blue" } }, "actions_capability_media_response_audio": { "name": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh/contexts/actions_capability_media_response_audio", "parameters": { "color": "blue", "color.original": "blue" } } }, "output": {} }, "incoming": { "parsed": [ "" ] }, "query": "blue", "data": {} }
4:19:11.346 PM dialogflowFirebaseFulfillment Headers { "host": "us-central1-actions-rwag.cloudfunctions.net", "user-agent": "Apache-HttpClient/4.5.4 (Java/1.8.0_181)", "transfer-encoding": "chunked", "accept": "text/plain, */*", "accept-charset": "big5, big5-hkscs, cesu-8, euc-jp, euc-kr, gb18030, gb2312, gbk, ibm-thai, ibm00858, ibm01140, ibm01141, ibm01142, ibm01143, ibm01144, ibm01145, ibm01146, ibm01147, ibm01148, ibm01149, ibm037, ibm1026, ibm1047, ibm273, ibm277, ibm278, ibm280, ibm284, ibm285, ibm290, ibm297, ibm420, ibm424, ibm437, ibm500, ibm775, ibm850, ibm852, ibm855, ibm857, ibm860, ibm861, ibm862, ibm863, ibm864, ibm865, ibm866, ibm868, ibm869, ibm870, ibm871, ibm918, iso-2022-cn, iso-2022-jp, iso-2022-jp-2, iso-2022-kr, iso-8859-1, iso-8859-13, iso-8859-15, iso-8859-2, iso-8859-3, iso-8859-4, iso-8859-5, iso-8859-6, iso-8859-7, iso-8859-8, iso-8859-9, jis_x0201, jis_x0212-1990, koi8-r, koi8-u, shift_jis, tis-620, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-32be, utf-32le, utf-8, windows-1250, windows-1251, windows-1252, windows-1253, windows-1254, windows-1255, windows-1256, windows-1257, windows-1258, windows-31j, x-big5-hkscs-2001, x-big5-solaris, x-compound_text, x-euc-jp-linux, x-euc-tw, x-eucjp-open, x-ibm1006, x-ibm1025, x-ibm1046, x-ibm1097, x-ibm1098, x-ibm1112, x-ibm1122, x-ibm1123, x-ibm1124, x-ibm1166, x-ibm1364, x-ibm1381, x-ibm1383, x-ibm300, x-ibm33722, x-ibm737, x-ibm833, x-ibm834, x-ibm856, x-ibm874, x-ibm875, x-ibm921, x-ibm922, x-ibm930, x-ibm933, x-ibm935, x-ibm937, x-ibm939, x-ibm942, x-ibm942c, x-ibm943, x-ibm943c, x-ibm948, x-ibm949, x-ibm949c, x-ibm950, x-ibm964, x-ibm970, x-iscii91, x-iso-2022-cn-cns, x-iso-2022-cn-gb, x-iso-8859-11, x-jis0208, x-jisautodetect, x-johab, x-macarabic, x-maccentraleurope, x-maccroatian, x-maccyrillic, x-macdingbat, x-macgreek, x-machebrew, x-maciceland, x-macroman, x-macromania, x-macsymbol, x-macthai, x-macturkish, x-macukraine, x-ms932_0213, x-ms950-hkscs, x-ms950-hkscs-xp, x-mswin-936, x-pck, x-sjis_0213, x-utf-16le-bom, x-utf-32be-bom, x-utf-32le-bom, x-windows-50220, x-windows-50221, x-windows-874, x-windows-949, x-windows-950, x-windows-iso2022jp", "content-type": "application/json; charset=UTF-8", "function-execution-id": "gjnwrdpyi1ax", "x-appengine-api-ticket": "e212b331d87bdb3c", "x-appengine-city": "?", "x-appengine-citylatlong": "0.000000,0.000000", "x-appengine-country": "US", "x-appengine-default-version-hostname": "l9ec7ba250478215b-tp.appspot.com", "x-appengine-https": "on", "x-appengine-region": "?", "x-appengine-request-log-id": "5bac13ef00ff00ffe3280c8cb3550001737e6c396563376261323530343738323135622d7470000139303866373866633530636138623435363966303164656633393333393136383a3233000100", "x-appengine-user-ip": "35.239.85.110", "x-cloud-trace-context": "0109e1b3b7dc8fbbefd2664dbcbd5d0a/2770932151653705781;o=1", "x-forwarded-for": "35.239.85.110, 35.239.85.110", "x-forwarded-proto": "https", "accept-encoding": "gzip" }
4:19:11.339 PM dialogflowFirebaseFulfillment Request { "responseId": "c7b55f8a-502d-431a-8056-258dec82268f", "queryResult": { "queryText": "blue", "parameters": { "color": "blue" }, "allRequiredParamsPresent": true, "fulfillmentMessages": [ { "text": { "text": [ "" ] } } ], "outputContexts": [ { "name": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh/contexts/actions_capability_screen_output", "parameters": { "color": "blue", "color.original": "blue" } }, { "name": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh/contexts/actions_capability_audio_output", "parameters": { "color": "blue", "color.original": "blue" } }, { "name": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh/contexts/google_assistant_input_type_keyboard", "parameters": { "color": "blue", "color.original": "blue" } }, { "name": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh/contexts/actions_capability_web_browser", "parameters": { "color": "blue", "color.original": "blue" } }, { "name": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh/contexts/actions_capability_media_response_audio", "parameters": { "color": "blue", "color.original": "blue" } } ], "intent": { "name": "projects/actions-rwag/agent/intents/8524ede6-72a2-467b-9b34-67a8f1d3a121", "displayName": "favorite color" }, "intentDetectionConfidence": 1, "languageCode": "en-us" }, "originalDetectIntentRequest": { "source": "google", "version": "2", "payload": { "isInSandbox": true, "surface": { "capabilities": [ { "name": "actions.capability.WEB_BROWSER" }, { "name": "actions.capability.MEDIA_RESPONSE_AUDIO" }, { "name": "actions.capability.SCREEN_OUTPUT" }, { "name": "actions.capability.AUDIO_OUTPUT" } ] }, "requestType": "SIMULATOR", "inputs": [ { "rawInputs": [ { "query": "blue", "inputType": "KEYBOARD" } ], "arguments": [ { "rawText": "blue", "textValue": "blue", "name": "text" } ], "intent": "actions.intent.TEXT" } ], "user": { "userStorage": "{\"data\":{}}", "lastSeen": "2018-09-26T23:19:06Z", "locale": "en-US", "userId": "ABwppHHp5yhn_VrB_SIGG93tCzMx9o0A_W9bIDlbCClkqcV85LrVbJ42vLQ7hWXfe3UOd7pASDIm6v_q" }, "conversation": { "conversationId": "ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh", "type": "ACTIVE", "conversationToken": "[]" }, "availableSurfaces": [ { "capabilities": [ { "name": "actions.capability.WEB_BROWSER" }, { "name": "actions.capability.SCREEN_OUTPUT" }, { "name": "actions.capability.AUDIO_OUTPUT" } ] } ] } }, "session": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh" }
4:19:11.063 PM dialogflowFirebaseFulfillment Function execution started
I think I've discovered why I was running into this problem, and why I couldn't explain it based on research into Actions on Google or Node.js. It looks like the page on my server that I was requesting returns a 301 "Permanently Moved" response. When I request the page through a web browser, it ignores(?) this response and serves the page anyway, but when I make the request in my AoG intent fulfillment, it silently recognizes the 301 and doesn't ever hit the PHP on the server. Anyway, it appears this is a problem with my server configuration and not my AoG code.
Hot tip to new AoG programmers: console.log() commands in the fulfillment will appear in the Firebase Cloud Functions log, which is what eventually allowed me to see the 301 code being returned. Thanks to anyone how tried to puzzle this out with me!
i have geojson data:
{
"type":"FeatureCollection",
"metadata":{
"generated":1417015873000,
11-26T14:33:40&endtime=2014-11-26T14:33:45",
"title":"USGS Earthquakes",
"status":200,
"api":"1.0.13",
"count":1
},
"features":
[{
"type":"Feature",
"properties":
{
"mag":6.8,
"place":"160km NW of Kota Ternate, Indonesia",
"time":1417012423350,"updated":1417015584000,
"tz":480,
"url":"http://comcat.cr.usgs.gov/earthquakes/eventpage/usb000t08w",
"detail":"http://comcat.cr.usgs.gov/fdsnws/event/1/query?eventid=usb000t08w&format=geojson",
"felt":1,
"cdi":5,
"mmi":4.98,
"alert":"green",
"status":"reviewed",
"tsunami":1,
"sig":712,
"net":"us",
"code":"b000t08w",
"ids":",at00nfnhsd,pt14330000,usb000t08w,",
"sources":",at,pt,us,",
"types":",cap,dyfi,general-link,geoserve,impact-link,losspager,moment-tensor,nearby-cities,origin,phase-data,shakemap,tectonic-summary,",
"nst":null,
"dmin":1.45,
"rms":1.32,
"gap":37,
"magType":"mwb",
"type":"earthquake",
"title":"M 6.8 - 160km NW of Kota Ternate, Indonesia"
},
"geometry":{"type":"Point","coordinates":[126.5456,1.9752,41.06]},
"id":"usb000t08w"
}]
}
how to parse value "title" ?
var geojson = JSON.parse(geojson_data);
Turns the geojson string into an object, from there you can get whatever you values you want from it.
Edit: your json is invalid, where are you getting the data from? I cleaned it up, so you can call JSON.parse on it. However, it is not valid geojson, so I'd double check where you come up with the data. This geojson validator might help.
{
"metadata": {
"generated": 1417015873000,
"11-26T14: 33: 40&endtime=2014-11-26T14: 33": 45,
"title": "USGSEarthquakes",
"status": 200,
"api": "1.0.13",
"count": 1
},
"features": [
{
"type": "Feature",
"properties": {
"mag": 6.8,
"place": "160km NW of Kota Ternate, Indonesia",
"time": 1417012423350,
"updated": 1417015584000,
"tz": 480,
"url": "http://comcat.cr.usgs.gov/earthquakes/eventpage/usb000t08w",
"detail": "http://comcat.cr.usgs.gov/fdsnws/event/1/query?eventid=usb000t08w&format=geojson",
"felt": 1,
"cdi": 5,
"mmi": 4.98,
"alert": "green",
"status": "reviewed",
"tsunami": 1,
"sig": 712,
"net": "us",
"code": "b000t08w",
"ids": ",at00nfnhsd,pt14330000,usb000t08w,",
"sources": ",at,pt,us,",
"types": ",cap,dyfi,general-link,geoserve,impact-link,losspager,moment-tensor,nearby-cities,origin,phase-data,shakemap,tectonic-summary,",
"nst": null,
"dmin": 1.45,
"rms": 1.32,
"gap": 37,
"magType": "mwb",
"type": "earthquake",
"title": "M 6.8 - 160km NW of Kota Ternate, Indonesia"
},
"geometry": {
"type": "Point",
"coordinates": [
126.5456,
1.9752,
41.06
]
},
"id": "usb000t08w"
}
]
}
I am having a struggle finding out why the following is happening in a application i'm developing:
So i read a JSON file where i want to read and save his content on localStorage, which in a chrome app is chrome.storage.local
So i get the following from a json file:
{
"schedule": {
"id": "416a18d6-7e42-4f8a-ac24-e902abe76f39",
"name": "blabla",
"updatedOn": "2013-09-08T16:34:41.000Z",
"etag": "esxrdctfvygbuhnij5464df7g8hu",
"applications": [
{
"id": "app001",
"type": "text/html",
"src": "http://www.google.com"
},
{
"id": "app002",
"type": "text/html",
"src": "http://www.stackoverflow.com"
}
],
"normalContent": [
{
"layout_id": "layout001",
"layout_name": "layout1",
"layout_dur": "indefinite",
"regions": [
{
"region_id": "region001",
"region_name": "regiao1",
"left": "0",
"top": "0",
"width": "0.5",
"height": "1",
"minWidth": "0",
"minHeight": "0",
"scheduleItem": "container",
"limitCycle": "1",
"selector": "seq",
"containerList": [
{
"cid": "app001",
"dur": "25"
},
{
"cid": "app002",
"dur": "15"
}
]
},
{
"region_id": "region002",
"region_name": "regiao2",
"left": "0.5",
"top": "0",
"width": "0.5",
"height": "1",
"minWidth": "0",
"minHeight": "0",
"scheduleItem": "container",
"limitCycle": "1",
"selector": "seq",
"containerList": [
{
"cid": "app002",
"dur": "15"
},
{
"cid": "app001",
"dur": "15"
}
]
}
]
}
]
}
}
So i get this and then i save the content in storage using:
chrome.storage.local.set({playerSchedule:this.schedule}, function(){
console.log('saved!')
});
Later on when i read the content stored using:
chrome.storage.local.get(["playerSchedule", "playerScheduleType"], function (res) {
self.currentSchedule = res.playerSchedule;
self.scheduleType = res.playerScheduleType;
});
This is what i get:
{
"schedule": {
"applications": [
{
"id": "app001",
"type": "text/html",
"src": "http://www.google.com"
},
{
"id": "app002",
"type": "text/html",
"src": "http://www.stackoverflow.com"
}
],
"etag": "esxrdctfvygbuhnij5464df7g8hu",
"id": "416a18d6-7e42-4f8a-ac24-e902abe76f39",
"name": "blabla",
"normalContent": [
{
"layout_dur": "indefinite",
"layout_id": "layout001",
"layout_name": "layout1",
"regions": [
{
...
"containerList": [
]
},
{
...
"containerList": [
]
}
]
}
],
"updatedOn": "2013-09-08T16:34:41.000Z"
}
}
As you can observe, the content i read comes in alphabetic order and the content in containerList is empty. Any reason why this is happening? I solved this by converting the object to string and storing it, but i wonder why saving as object i get that from reading as an object or is there something i am missing?
Thanks in advance.
This is probably http://code.google.com/p/chromium/issues/detail?id=277647. Fix is in the works for Chrome 31.