I don't understand why I am getting NaN. Is there something I am missing, could be the object, or my code ?
$(document).ready(function() {
var text = {
"kind": "books#volume",
"id": "Wfan6L9RGgYC",
"etag": "UlsLzySUlh0",
"selfLink": "https://www.googleapis.com/books/v1/volumes/Wfan6L9RGgYC",
"volumeInfo": {
"title": "The Modern Web",
"subtitle": "Multi-device Web Development with HTML5, CSS3, and JavaScript",
"": [
"Peter Gasston"
],
"publisher": "No Starch Press",
"publishedDate": "2013",
"description": "<p><b>A Guide to Modern Web Development</b><br></p><p>Today's web technologies are evolving at near-light speed, bringing the promise of a seamless Internet ever closer to reality. When users can browse the Web on a three-inch phone screen as easily as on a fifty-inch HDTV, what's a developer to do?</p><p>Peter Gasston's <i>The Modern Web</i> will guide you through the latest and most important tools of device-agnostic web development, including HTML5, CSS3, and JavaScript. His plain-English explanations and practical examples emphasize the techniques, principles, and practices that you'll need to easily transcend individual browser quirks and stay relevant as these technologies are updated.</p><p>Learn how to:</p><p>* Plan your content so that it displays fluidly across multiple devices<br>* Design websites to interact with devices using the most up-to-date APIs, including Geolocation, Orientation, and Web Storage<br>* Incorporate cross-platform audio and video without using troublesome plug-ins<br>* Make images and graphics scalable on high-resolution devices with SVGUse powerful HTML5 elements to design better forms</p><p>Turn outdated websites into flexible, user-friendly ones that take full advantage of the unique capabilities of any device or browser. With the help of <i>The Modern Web</i>, you'll be ready to navigate the front lines of device-independent development.</p>",
"industryIdentifiers": [{
"type": "ISBN_10",
"identifier": "1593274874"
}, {
"type": "ISBN_13",
"identifier": "9781593274870"
}],
"readingModes": {
"text": true,
"image": true
},
"pageCount": 264,
"printedPageCount": 266,
"dimensions": {
"height": "24.00 cm",
"width": "17.80 cm",
"thickness": "1.50 cm"
},
"printType": "BOOK",
"categories": [
"Computers / Software Development & Engineering / General",
"Computers / Web / Design"
],
"averageRating": 4.5,
"ratingsCount": 3,
"maturityRating": "NOT_MATURE",
"allowAnonLogging": true,
"contentVersion": "1.2.2.0.preview.3",
"imageLinks": {
"smallThumbnail": "http://books.google.com/books/content?id=Wfan6L9RGgYC&printsec=frontcover&img=1&zoom=5&edge=curl&imgtk=AFLRE72KO7jCxe5uWt_wdrgHfdSNO_raoAKYbPNaAILa300r3DxeVHIqEeZto77JClWzw41ZwwbcMlVl2Ki9dF_ycIEUDhwbetDSF6K112O_XoebMDRoRNA5vskWyCtpGig-LaVPbE7j&source=gbs_api",
"thumbnail": "http://books.google.com/books/content?id=Wfan6L9RGgYC&printsec=frontcover&img=1&zoom=1&edge=curl&imgtk=AFLRE70to3PUyJeiv-brcBCzs330NDwRGM4cYu9gHzdVNLrIEn7ghBo5Gms9MAFxQ8ZkRt0-JZhCJq7T0V_vOLwMhDu4f_2icMtDrO5bMPSqRa4EuB9-3XGaNH-UxsYBvJIMUadwdd4Y&source=gbs_api",
"small": "http://books.google.com/books/content?id=Wfan6L9RGgYC&printsec=frontcover&img=1&zoom=2&edge=curl&imgtk=AFLRE709uVhXoOlgZxdwB4DKF0X1zVPvV7_4EA_PvhNlIGLKknTSsZiIoDnsJPsswWKBQIoSC-gJ0vOe_4kTiWPU38xZydOliDp5u0SxJqqFbDIKnz-KxprkLg7Ze2fxJWGBXRQSgHJA&source=gbs_api",
"medium": "http://books.google.com/books/content?id=Wfan6L9RGgYC&printsec=frontcover&img=1&zoom=3&edge=curl&imgtk=AFLRE72idQ0vc5gY408WHZTWFY8AOQLhGVbI4ktB4O6NXQFbbHY0VrM0PJWA_XF_98_NThQtP8tvw73qpSwqkGoi-QKzMPfi_M75VzK-zbxVsFZ_rtfeMGHWREhGACvV-F39BhQ1WXwt&source=gbs_api",
"large": "http://books.google.com/books/content?id=Wfan6L9RGgYC&printsec=frontcover&img=1&zoom=4&edge=curl&imgtk=AFLRE73M-PJZ0bTkffdLAwU427ppNpxsenoBSi91ABnrm4lNMPwOBNDIL23OTK7ZNvGlGChk9klXAP3DDoQbLXPwct-F_m9j1KKJ4w77HkeP69-eYdwxW1Z5iNgVYqyZCRj3AkAHmOaZ&source=gbs_api",
"extraLarge": "http://books.google.com/books/content?id=Wfan6L9RGgYC&printsec=frontcover&img=1&zoom=6&edge=curl&imgtk=AFLRE70yPdCZ5tbR5aL9WbnodE4Uf263MR_bPekV6tab5QKe193uKXqXqilaTmc-bByqZGmaEk38KBic64e-dp8VON30C-E7eJP-TR-6cjVA3dmVTARYkMGMiE5dQsPsMGO2z_6p4ryx&source=gbs_api"
},
"language": "en",
"previewLink": "http://books.google.com/books?id=Wfan6L9RGgYC&hl=&source=gbs_api",
"infoLink": "http://books.google.com/books?id=Wfan6L9RGgYC&hl=&source=gbs_api",
"canonicalVolumeLink": "http://books.google.com/books/about/The_Modern_Web.html?hl=&id=Wfan6L9RGgYC"
},
"layerInfo": {
"layers": [{
"layerId": "geo",
"volumeAnnotationsVersion": "8"
}]
},
"saleInfo": {
"country": "US",
"saleability": "FOR_SALE",
"isEbook": true,
"listPrice": {
"amount": 27.95,
"currencyCode": "USD"
},
"retailPrice": {
"amount": 15.37,
"currencyCode": "USD"
},
"buyLink": "http://books.google.com/books?id=Wfan6L9RGgYC&hl=&buy=&source=gbs_api",
"offers": [{
"finskyOfferType": 1,
"listPrice": {
"amountInMicros": 27950000,
"currencyCode": "USD"
},
"retailPrice": {
"amountInMicros": 15370000,
"currencyCode": "USD"
},
"giftable": true
}]
},
"accessInfo": {
"country": "US",
"viewability": "PARTIAL",
"embeddable": true,
"publicDomain": false,
"textToSpeechPermission": "ALLOWED",
"epub": {
"isAvailable": true
},
"pdf": {
"isAvailable": true
},
"webReaderLink": "http://books.google.com/books/reader?id=Wfan6L9RGgYC&hl=&printsec=frontcover&output=reader&source=gbs_api",
"accessViewStatus": "SAMPLE",
"quoteSharingAllowed": false
}
}
$.each(text, function(i, value) {
$('</p>').appendTo("#container").text(text[i].title + text[i].subtitle);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="container">
</div>
Your $.each function is looping through every property at the root of your object, and the way your object is structured, not every property has a nested title or subtitle property.
You would either have to structure your object consistently, or check for the properties you need before you try to access them.
Related
I'm running a simple custom Google Chrome startpage consisting of a background .gif and a google searchbar. However, Google Chrome interprets it as something other than the default startpage, and thus won't show the native bookmark bar, unless the option to show it everywhere is checked (which is awkard for my monitor resolution).
The Google Chrome bookmarks file is located at C:\Users\UserName\AppData\Local\Google\Chrome\User Data\Default\bookmarks,below I'll paste a sample of its structure.
Just looking at this, do you think there's a way to either show the native bookmark ONLY in my custom startpage, or to fetch the information in that bookmarks file and display it on my own?
{
"checksum": "REDACTED",
"roots": {
"bookmark_bar": {
"children": [ {
"children": [ {
"date_added": "13222412798372622",
"date_last_used": "0",
"guid": "REDACTED",
"id": "7",
"name": "Whatsapp",
"type": "url",
"url": "https://web.whatsapp.com/"
}, {
"date_added": "13126908348807315",
"date_last_used": "13317078268398707",
"guid": "REDACTED",
"id": "8",
"meta_info": {
"last_visited_desktop": "REDACTED"
},
"name": "YouTube",
"type": "url",
"url": "https://www.youtube.com/feed/subscriptions"
}, {
"date_added": "13126908407318057",
"date_last_used": "13317078266263899",
"guid": "REDACTED",
"id": "9",
"meta_info": {
"last_visited_desktop": "REDACTED"
},
I'm looking solution to query JSON that extracts specific data.
This solution will be embedded inside our Python software (more exactly Python AWS Lambda) and the user should have the ability to specify such query string in GUI.
For example, we have such JSON and I would extract "nazwisko_weterynarza.value" from "files" array if "typ_dokument" is equal to "szczepienie" and "data_szczepienia" is equal to 3434343.
I've tried this using JSON Path but I've failed.
What about embedded Lua/Javascript in Python, but how to create a 'sandbox' to be sure that such a solution will be safe?
{
"files" :
[
{
"meta": {
"updated": 555555,
"attributes": [
{
"typ_dokumentu":
{
"formula_type": "NONE",
"formula": "",
"value_type": "string",
"value": "szczepienie",
"updated": 5345435435345
}
},
{
"data_szczepienia":
{
"formula_type": "NONE",
"formula": "",
"value_type": "int",
"value": 3434343,
"updated": 5345435225345
},
},
{
"nazwisko_weterynarza":
{
"formula_type": "NONE",
"formula": "",
"value_type": "string",
"value": "Nowak",
"updated": 5345435225345
}
}
]
}
},
{
"meta": {
"updated": 555555,
"attributes": [
{
"typ_dokumentu" :
{
"formula_type": "NONE",
"formula": "",
"value_type": "string",
"value": "Certyfikat urodzin",
"updated": 5345435435345
}
},
{
"data_urodzin" :
{
"formula_type": "NONE",
"formula": "",
"value_type": "int",
"value": 8888888,
"updated": 5345435225345
}
}
]
}
}
]
}
The AWS JSON (reference) path queries are not capable enough. Some more advanced JSONPath processors can do it, eg. using Jayway's JsonPath we could run a query like this:
$.files..meta.[?(#.attributes[*].typ_dokumentu.value contains 'szczepienie' && #.attributes[*].data_szczepienia.value contains '3434343')]..nazwisko_weterynarza.value
Reurns ["Nowak"] (You can try it online).
I don't know what you mean by embedded JavaScript/Lua, but in any event, you could create a web service that does the querying for you leveraging an implementation of your choice. Security wouldn't be an issue as long as your API is properly secured.
Question:
Is there a plain or native javascript way to validate a JSON script against a JSON schema?
I have found lots of libraries on Github, but no native/plain solution. Does EcmaScript not have a specification for this? and do none of the browsers (or nodejs) have a way to validate JSON natively?
Context of Question:
I have a very complex schema that I developed.
It is supposed to work along with a script that requires that the JSON data passed into it to comply with the schema.
Simply, no.
There was something called JSON Schema, which was an Internet Draft which expired in 2013. Internet Drafts are the first stage to producing an Internet Standard. See more about it at the official site, as it seems to potentially still be actively developed, although it is not (to my knowledge) in widespread use.
An example of the schema:
{
"$schema": "http://json-schema.org/schema#",
"title": "Product",
"type": "object",
"required": ["id", "name", "price"],
"properties": {
"id": {
"type": "number",
"description": "Product identifier"
},
"name": {
"type": "string",
"description": "Name of the product"
},
"price": {
"type": "number",
"minimum": 0
},
"tags": {
"type": "array",
"items": {
"type": "string"
}
},
"stock": {
"type": "object",
"properties": {
"warehouse": {
"type": "number"
},
"retail": {
"type": "number"
}
}
}
}
}
will validate this example JSON:
{
"id": 1,
"name": "Foo",
"price": 123,
"tags": [
"Bar",
"Eek"
],
"stock": {
"warehouse": 300,
"retail": 20
}
}
There seems to be at least one pure JS solution now (https://github.com/tdegrunt/jsonschema) available via npm (https://www.npmjs.com/package/jsonschema). I am not a contributor, although I appreciate their work.
I'm having trouble in showing the latest post of my Facebook page in my website without using PHP since the website is not hosted in an Apache server.
What I've done till now:
Created a Facebook app and generated an Access token.
Access to Facebook Developer Graph explorer, and used GET method
https://developers.facebook.com/tools/explorer?method=GET&path=nextgenerationmorocco%2Ffeed%3Flimit%3D1&version=v2.0
The result after clicking on Graph Explorer submit button:
{
"data": [
{
"id": "421944571240838_501444706624157",
"from": {
"category": "Organization",
"category_list": [
{
"id": "162237190493977",
"name": "Computer Training"
},
{
"id": "108472109230615",
"name": "Computer Services"
}
],
"name": "Next Generation I.T.",
"id": "421944571240838"
},
"message": "Inscriptions ouvertes pour la formation symfony2\nProfil du formateur : Ingénieur d'état, 5 ans d'expérience.",
"picture": "https://fbexternal-a.akamaihd.net/safe_image.php?d=AQCyB9kEztxV2fnb&w=154&h=154&url=http%3A%2F%2Fngitmaroc.com%2Fimg%2Fportfolio%2Fformation-web-1.jpg",
"link": "http://ngitmaroc.com/formation-web.html",
"name": "Formation Web",
"caption": "ngitmaroc.com",
"description": "Formation programmation/développement site application web php5 symfony2 Maroc Oujda",
"icon": "https://fbstatic-a.akamaihd.net/rsrc.php/v2/yD/r/aS8ecmYRys0.gif",
"privacy": {
"value": ""
},
"type": "link",
"status_type": "shared_story",
"created_time": "2014-06-01T12:17:22+0000",
"updated_time": "2014-06-01T12:17:22+0000",
"likes": {
"data": [
{
"id": "1459899217586855",
"name": "Nassira Said"
},
{
"id": "1484688285098548",
"name": "Mohamed Tizaoui"
},
{
"id": "1458333711077710",
"name": "Hasnae Lazaar"
},
{
"id": "574623632656391",
"name": "KaOûtar OuJdiia"
}
],
"paging": {
"cursors": {
"after": "NTc0NjIzNjMyNjU2Mzkx",
"before": "MTQ1OTg5OTIxNzU4Njg1NQ=="
}
}
}
}
],
"paging": {
"previous": "https://graph.facebook.com/v2.0/421944571240838/feed?limit=1&since=1401625042",
"next": "https://graph.facebook.com/v2.0/421944571240838/feed?limit=1&until=1401625041"
}
}
How can I use Javascript to fetch these information and show them on my website : "message", "from", "created_time"? Any help will be highly appreciated since I'm new to Javascript and Facebook developers!
You alternatively may use Facebook Likebox plugin to show your recent posts in your website.
I have QML LocalStorage using javaScript. In it I put object via JSON.stringify(). When I try to read the object from DB using JSON.parse() is returning : scanEscape a and I did't found a reference to this scan error JSON file:
{
"header": {
"version": "2.5",
"createdIn": "PickWorks - Linux",
"modifiedIn": "PickWorks.appName",
"modified": "2013/12/07"
},
"properties": {
"title": "We found a love",
"authors": [
{
"name": "Rihana"
}
],
"transposition": -2,
"tempo": {
"type": "bpm",
"value": "130"
},
"key": "C",
"version": "2.5.4",
"publisher": "GuitarTab",
"keywords": [
"find",
"love",
"deny"
],
"verseOrder": "v1 b c v2 b c",
"themes": [
"love",
"hopeless"
]
},
"lyrics": [
{
"title": "v1",
"text": "[a]Yellow diamonds [F]in the light\n[C]And we're standing [G]side by side\n[a]As your shadow [F]crosses mine\n[C]What it takes to [G]come [a]alive.[F]\n",
"items": {}
},
{
"title": "v2",
"text": "[a]Shine a light through [F]an open door\n[C]Love and life [G]I will divide\n[a]Turn away cause [F]I need you more\n[C]Feel the heart-[G]beat in my [a]mind.[F]\n"
},
{
"title": "c",
"text": "[a]We found love in a [F]hopeless place\n[C]We found love in a [G]hopeless place\n[a]We found love in a [F]hopeless place\n[C]We found love in a [G]hopeless place\n"
},
{
"title": "b",
"text": "[C]It's the way I'm feeling [G]I just can't [a]deny.[F]\n[C]But I've gotta [G]let it go\n"
}
]
}
Q1: What is this error ?
Q2: How to solve it?
P.S.: (Tested on Qt 5.2b & 5.1.1)
Bug was actually some missed debugging log in Qt. Upon creating Bugtrack issue problem was adressed and will be solved in next stable release (Qt 5.2.0).