I'm working with the Google's API to get the info of my contact list and after use console log
function fetch(token) {
$.ajax({
url: "https://www.google.com/m8/feeds/contacts/default/full?access_token=" + token.access_token + "&alt=json",
dataType: "JSON",
success:function(data) {
var json = JSON.stringify(data);
console.log(json);
}
});
}
I'm getting this info
{
"version": "1.0",
"encoding": "UTF-8",
"feed": {
"xmlns": "http://www.w3.org/2005/Atom",
"xmlns$openSearch": "http://a9.com/-/spec/opensearchrss/1.0/",
"xmlns$batch": "http://schemas.google.com/gdata/batch",
"xmlns$gd": "http://schemas.google.com/g/2005",
"xmlns$gContact": "http://schemas.google.com/contact/2008",
"id": {
"$t": "sifo.contacto#gmail.com"
},
"updated": {
"$t": "2016-02-22T19:33:36.064Z"
},
"category": [{
"scheme": "http://schemas.google.com/g/2005#kind",
"term": "http://schemas.google.com/contact/2008#contact"
}],
"title": {
"type": "text",
"$t": "Sifo Sistema Inteligente de Facturación Online's Contacts"
},
"link": [{
"rel": "alternate",
"type": "text/html",
"href": "http://www.google.com/"
}, {
"rel": "http://schemas.google.com/g/2005#feed",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/sifo.contacto%40gmail.com/full"
}, {
"rel": "http://schemas.google.com/g/2005#post",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/sifo.contacto%40gmail.com/full"
}, {
"rel": "http://schemas.google.com/g/2005#batch",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/sifo.contacto%40gmail.com/full/batch"
}, {
"rel": "self",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/sifo.contacto%40gmail.com/full?alt=json&max-results=25"
}, {
"rel": "next",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/sifo.contacto%40gmail.com/full?alt=json&start-index=26&max-results=25"
}],
"author": [{
"name": {
"$t": "Sifo Sistema Inteligente de Facturación Online"
},
"email": {
"$t": "sifo.contacto#gmail.com"
}
}],
"generator": {
"version": "1.0",
"uri": "http://www.google.com/m8/feeds",
"$t": "Contacts"
},
"openSearch$totalResults": {
"$t": "704"
},
"openSearch$startIndex": {
"$t": "1"
},
"openSearch$itemsPerPage": {
"$t": "25"
},
"entry": [{
"id": {
"$t": "http://www.google.com/m8/feeds/contacts/sifo.contacto%40gmail.com/base/1600788a7596f9"
},
"updated": {
"$t": "2015-10-08T19:48:21.315Z"
},
"category": [{
"scheme": "http://schemas.google.com/g/2005#kind",
"term": "http://schemas.google.com/contact/2008#contact"
}],
"title": {
"type": "text",
"$t": "Lic. Jose Lugo"
},
"link": [{
"rel": "http://schemas.google.com/contacts/2008/rel#edit-photo",
"type": "image/*",
"href": "https://www.google.com/m8/feeds/photos/media/sifo.contacto%40gmail.com/1600788a7596f9/1B2M2Y8AsgTpgAmY7PhCfg"
}, {
"rel": "self",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/sifo.contacto%40gmail.com/full/1600788a7596f9"
}, {
"rel": "edit",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/sifo.contacto%40gmail.com/full/1600788a7596f9/1444333701315001"
}],
"gd$email": [{
"rel": "http://schemas.google.com/g/2005#other",
"address": "jose.lugo#mecrg.com",
"primary": "true"
}]
}, {
"id": {
"$t": "http://www.google.com/m8/feeds/contacts/sifo.contacto%40gmail.com/base/243862896da102"
},
"updated": {
"$t": "2016-02-11T22:58:30.580Z"
},
"category": [{
"scheme": "http://schemas.google.com/g/2005#kind",
"term": "http://schemas.google.com/contact/2008#contact"
}],
"title": {
"type": "text",
"$t": ""
},
"link": [{
"rel": "http://schemas.google.com/contacts/2008/rel#edit-photo",
"type": "image/*",
"href": "https://www.google.com/m8/feeds/photos/media/sifo.contacto%40gmail.com/243862896da102/qPx9RZ6Tppge180vMVnHUw"
}, {
"rel": "http://schemas.google.com/contacts/2008/rel#photo",
"type": "image/*",
"href": "https://www.google.com/m8/feeds/photos/media/sifo.contacto%40gmail.com/243862896da102"
}, {
"rel": "self",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/sifo.contacto%40gmail.com/full/243862896da102"
}, {
"rel": "edit",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/sifo.contacto%40gmail.com/full/243862896da102/1455231510580001"
}],
"gd$email": [{
"rel": "http://schemas.google.com/g/2005#other",
"address": "sharai.alvarez#gmail.com",
"primary": "true"
}]
}, {
"id": {
"$t": "http://www.google.com/m8/feeds/contacts/sifo.contacto%40gmail.com/base/406bac09eee821"
},
"updated": {
"$t": "2016-02-11T16:26:46.318Z"
},
"category": [{
"scheme": "http://schemas.google.com/g/2005#kind",
"term": "http://schemas.google.com/contact/2008#contact"
}],
"title": {
"type": "text",
"$t": ""
},
"link": [{
"rel": "http://schemas.google.com/contacts/2008/rel#edit-photo",
"type": "image/*",
"href": "https://www.google.com/m8/feeds/photos/media/sifo.contacto%40gmail.com/406bac09eee821/1B2M2Y8AsgTpgAmY7PhCfg"
}, {
"rel": "self",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/sifo.contacto%40gmail.com/full/406bac09eee821"
}, {
"rel": "edit",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/sifo.contacto%40gmail.com/full/406bac09eee821/1455208006318001"
}],
"gd$email": [{
"rel": "http://schemas.google.com/g/2005#other",
"address": "rosyalonso3#hotmail.com",
"primary": "true"
}]
}, {
"id": {
"$t": "http://www.google.com/m8/feeds/contacts/sifo.contacto%40gmail.com/base/48a21c08062798"
},
"updated": {
"$t": "2016-02-18T21:08:19.835Z"
},
"category": [{
"scheme": "http://schemas.google.com/g/2005#kind",
"term": "http://schemas.google.com/contact/2008#contact"
}],
"title": {
"type": "text",
"$t": ""
},
"link": [{
"rel": "http://schemas.google.com/contacts/2008/rel#edit-photo",
"type": "image/*",
"href": "https://www.google.com/m8/feeds/photos/media/sifo.contacto%40gmail.com/48a21c08062798/1B2M2Y8AsgTpgAmY7PhCfg"
}, {
"rel": "self",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/sifo.contacto%40gmail.com/full/48a21c08062798"
}, {
"rel": "edit",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/sifo.contacto%40gmail.com/full/48a21c08062798/1455829699835001"
}],
"gd$email": [{
"rel": "http://schemas.google.com/g/2005#other",
"address": "joseluisgr15#yahoo.com",
"primary": "true"
}]
}, {
"id": {
"$t": "http://www.google.com/m8/feeds/contacts/sifo.contacto%40gmail.com/base/596ac60cfe288f"
},
"updated": {
"$t": "2015-06-10T21:01:08.157Z"
},
"category": [{
"scheme": "http://schemas.google.com/g/2005#kind",
"term": "http://schemas.google.com/contact/2008#contact"
}],
"title": {
"type": "text",
"$t": "FLORA EXOTICA DE CHIAPAS"
},
"link": [{
"rel": "http://schemas.google.com/contacts/2008/rel#edit-photo",
"type": "image/*",
"href": "https://www.google.com/m8/feeds/photos/media/sifo.contacto%40gmail.com/596ac60cfe288f/1B2M2Y8AsgTpgAmY7PhCfg"
}, {
"rel": "self",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/sifo.contacto%40gmail.com/full/596ac60cfe288f"
}, {
"rel": "edit",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/sifo.contacto%40gmail.com/full/596ac60cfe288f/1433970068157001"
}],
"gd$email": [{
"rel": "http://schemas.google.com/g/2005#other",
"address": "tropiflores#hotmail.com",
"primary": "true"
}]
}, {
"id": {
"$t": "http://www.google.com/m8/feeds/contacts/sifo.contacto%40gmail.com/base/69c8d608c00f66"
},
"updated": {
"$t": "2016-01-07T17:00:01.946Z"
},
"category": [{
"scheme": "http://schemas.google.com/g/2005#kind",
"term": "http://schemas.google.com/contact/2008#contact"
}],
"title": {
"type": "text",
"$t": ""
},
"link": [{
"rel": "http://schemas.google.com/contacts/2008/rel#edit-photo",
"type": "image/*",
"href": "https://www.google.com/m8/feeds/photos/media/sifo.contacto%40gmail.com/69c8d608c00f66/bc1NAkUY9UZ5B9Ih8I16dw"
}, {
"rel": "http://schemas.google.com/contacts/2008/rel#photo",
"type": "image/*",
"href": "https://www.google.com/m8/feeds/photos/media/sifo.contacto%40gmail.com/69c8d608c00f66"
}, {
"rel": "self",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/sifo.contacto%40gmail.com/full/69c8d608c00f66"
}, {
"rel": "edit",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/sifo.contacto%40gmail.com/full/69c8d608c00f66/1452186001946000"
}],
"gd$email": [{
"rel": "http://schemas.google.com/g/2005#other",
"address": "Omarpuribe#gmail.com",
"primary": "true"
}]
}, {
"id": {
"$t": "http://www.google.com/m8/feeds/contacts/sifo.contacto%40gmail.com/base/8640870e6f72d7"
},
"updated": {
"$t": "2016-01-20T15:54:41.842Z"
},
"category": [{
"scheme": "http://schemas.google.com/g/2005#kind",
"term": "http://schemas.google.com/contact/2008#contact"
}],
"title": {
"type": "text",
"$t": ""
},
"link": [{
"rel": "http://schemas.google.com/contacts/2008/rel#edit-photo",
"type": "image/*",
"href": "https://www.google.com/m8/feeds/photos/media/sifo.contacto%40gmail.com/8640870e6f72d7/1B2M2Y8AsgTpgAmY7PhCfg"
}, {
"rel": "self",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/sifo.contacto%40gmail.com/full/8640870e6f72d7"
}, {
"rel": "edit",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/sifo.contacto%40gmail.com/full/8640870e6f72d7/1453305281842002"
}],
"gd$email": [{
"rel": "http://schemas.google.com/g/2005#other",
"address": "aguixcor#gmail.com",
"primary": "true"
}]
}, {
"id": {
"$t": "http://www.google.com/m8/feeds/contacts/sifo.contacto%40gmail.com/base/adb5708dff4555"
},
"updated": {
"$t": "2016-01-07T20:46:02.243Z"
},
"category": [{
"scheme": "http://schemas.google.com/g/2005#kind",
"term": "http://schemas.google.com/contact/2008#contact"
}],
"title": {
"type": "text",
"$t": ""
},
"link": [{
"rel": "http://schemas.google.com/contacts/2008/rel#edit-photo",
"type": "image/*",
"href": "https://www.google.com/m8/feeds/photos/media/sifo.contacto%40gmail.com/adb5708dff4555/1B2M2Y8AsgTpgAmY7PhCfg"
}, {
"rel": "self",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/sifo.contacto%40gmail.com/full/adb5708dff4555"
}, {
"rel": "edit",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/sifo.contacto%40gmail.com/full/adb5708dff4555/1452199562243000"
}],
"gd$email": [{
"rel": "http://schemas.google.com/g/2005#other",
"address": "Ponyjr12#hotmail.com",
"primary": "true"
}]
}, {
"id": {
"$t": "http://www.google.com/m8/feeds/contacts/sifo.contacto%40gmail.com/base/e5831f8fe0aeb2"
},
"updated": {
"$t": "2016-02-11T18:22:13.253Z"
},
"category": [{
"scheme": "http://schemas.google.com/g/2005#kind",
"term": "http://schemas.google.com/contact/2008#contact"
}],
"title": {
"type": "text",
"$t": ""
},
"link": [{
"rel": "http://schemas.google.com/contacts/2008/rel#edit-photo",
"type": "image/*",
"href": "https://www.google.com/m8/feeds/photos/media/sifo.c
and I would like to read the value of "address" to get the email address but I have no idea how, I tried with $.each but the value was "undefined" everytime, what should do I to reach the email?
what exactly were you trying to call $.each on? On the entire data object, or some property?
If you just want to get the list of email addresses, you can use a map function to iterate over the data.feed.entry array and pull out the nested gd$email[0].address value like this:
var emailAddresses = data.feed.entry.map(function(entry) {
//take the first gd$email item the entry has
var gdEmail = entry['gd$email'][0];
//this assumes all entries will have a gd$email,
// you may want to implement a null check
return gdEmail.address;
});
Related
I want the data (i.e value inside choices array) inside the red choiseSet when selected and clicked on the btn, I kept an image and added action submit as action.submit as that's my usecase, I am pretty much confused how I can do that, Here's the card payload
{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.2",
"body": [
{
"type": "Input.ChoiceSet",
"id": "myColor2",
"style": "expanded",
"value": "1",
"choices": [
{
"title": "Red",
"value": "1"
}
]
},
{
"type": "Image",
"altText": "it's a image",
"url": "https://media.istockphoto.com/vectors/bhutanese-ngultrum-btn-vector-id1304476894",
"width": "100px",
"height": "100px",
"horizontalAlignment": "Left",
"selectAction": {
"type": "Action.Submit",
"id": "btn",
"title": "btn"
}
}
]
}
Once submitted by clicking on the icon, the bot should receive an activity of type message but with no text. The data you want is in the value property.
{
"activity": {
"channelData": {
"postBack": true,
"clientActivityID": "<REMOVED>",
"clientTimestamp": "2022-04-05T18:43:17.348Z"
},
"type": "message",
"value": {
"myColor2": "1"
},
"channelId": "emulator",
"from": {
"id": "<REMOVED>",
"name": "",
"role": "user"
},
"locale": "en-us",
"localTimestamp": "2022-04-05T11:43:17-07:00",
"localTimezone": "America/Los_Angeles",
"timestamp": "2022-04-05T18:43:17.408Z",
"id": "<REMOVED>",
"recipient": {
"id": "<REMOVED>",
"name": "Bot",
"role": "bot"
},
"conversation": {
"id": "<REMOVED>"
},
"serviceUrl": "http://localhost:3212"
},
"id": "<REMOVED>",
"timestamp": 1649184197408
}
I am trying to play around with react-jsonschema form of Mozilla.
I have my jsonschema as
{
"definitions": {
"address": {
"type": "object",
"properties": {
"street_address": {
"type": "string"
},
"city": {
"type": "string"
},
"state": {
"type": "string"
}
},
"required": [
"street_address",
"city",
"state"
]
},
"node": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"children": {
"type": "array",
"items": {
"$ref": "#/definitions/node"
}
}
}
}
},
"type": "object",
"properties": {
"billing_address": {
"title": "Billing address",
"$ref": "#/definitions/address"
},
"shipping_address": {
"title": "Shipping address",
"$ref": "#/definitions/address"
},
"tree": {
"title": "Recursive references",
"$ref": "#/definitions/node"
}
}
}
UiSchema as
{
"ui:order": [
"shipping_address",
"billing_address",
"tree"
]
}
Using reorder I can control the order of controls on the ui, but as shipping address has street address,city and state. How can I control the ui:order of these controls, consider I want city to appear first within shipping address, how can I do that using Mozilla React jsonschema form.
You can add order at the shipping address level.
{
"shipping_address": {
"ui:order": [
"city",
"*"
]
},
"ui:order": [
"shipping_address",
"billing_address",
"tree"
]
}
Try #ver01/form here
with schema this:
{
"definitions": {
"address": {
"type": "object",
"properties": {
"street_address": {
"title": "street_address",
"type": "string"
},
"city": {
"title": "city",
"type": "string"
},
"state": {
"title": "state",
"type": "string"
}
},
"required": [
"street_address",
"city",
"state"
]
},
"node": {
"type": "object",
"properties": {
"name": {
"title": "name",
"type": "string"
},
"children": {
"title": "children",
"type": "array",
"items": {
"$ref": "#/definitions/node"
}
}
}
}
},
"type": "object",
"properties": {
"billing_address": {
"title": "Billing address",
"$ref": "#/definitions/address"
},
"shipping_address": {
"title": "Shipping address",
"$ref": "#/definitions/address",
"$vf_opt": {
"option": {
"order": [
"city",
"*"
]
}
}
},
"tree": {
"title": "Recursive references",
"$ref": "#/definitions/node"
}
},
"$vf_opt": {
"option": {
"order": [
"shipping_address",
"billing_address",
"tree"
]
}
}
I am using Angular Schema Form to generate input fields for me. I am wondering if there is any way I could customize the input fields by adding IDs. I tried looking at the documentation (https://github.com/Textalk/angular-schema-form/blob/development/docs/index.md), but it doesn't seem like the current version supports it (only adding classes).
I've just done a bit of research and on the "Kitchen Sink" Example on -
http://schemaform.io/examples/bootstrap-example.html
they have used this code
Form:
`[
{
"type": "fieldset",
"title": "Stuff",
"items": [
{
"type": "tabs",
"tabs": [
{
"title": "Simple stuff",
"items": [
{
"key": "name",
"placeholder": "Check the console",
"onChange": "log(modelValue)",
"feedback": "{'glyphicon': true, 'glyphicon-ok': hasSuccess(), 'glyphicon-star': !hasSuccess() }"
},
{
"key": "favorite",
"feedback": false
}
]
},
{
"title": "More stuff",
"items": [
"attributes.eyecolor",
"attributes.haircolor",
{
"key": "attributes.shoulders.left",
"title": "Left shoulder",
"description": "This value is copied to attributes.shoulders.right in the model",
"copyValueTo": [
"attributes.shoulders.right"
]
},
{
"key": "shoesizeLeft",
"feedback": false,
"copyValueTo": [
"shoesizeRight"
]
},
{
"key": "shoesizeRight"
},
{
"key": "invitation",
"tinymceOptions": {
"toolbar": [
"undo redo| styleselect | bold italic | link image",
"alignleft aligncenter alignright"
]
}
},
"things",
"dislike"
]
}
]
}
]
},
{
"type": "help",
"helpvalue": "<hr>"
},
"soul",
{
"type": "conditional",
"condition": "modelData.soul",
"items": [
{
"key": "soulserial",
"placeholder": "ex. 666"
}
]
},
{
"key": "date",
"minDate": "2014-06-20"
},
{
"key": "radio",
"type": "radios",
"titleMap": [
{
"value": "Transistor",
"name": "Transistor <br> Not the tube kind."
},
{
"value": "Tube",
"name": "Tube <br> The tube kind."
}
]
},
{
"key": "radio2",
"type": "radios-inline",
"titleMap": [
{
"value": "Transistor",
"name": "Transistor <br> Not the tube kind."
},
{
"value": "Tube",
"name": "Tube <br> The tube kind."
}
]
},
{
"key": "radiobuttons",
"style": {
"selected": "btn-success",
"unselected": "btn-default"
},
"type": "radiobuttons",
"notitle": true
},
{
"type": "actions",
"items": [
{
"type": "submit",
"style": "btn-info",
"title": "Do It!"
},
{
"type": "button",
"style": "btn-danger",
"title": "Noooooooooooo",
"onClick": "sayNo()"
}
]
}
]`
Schema:
`{
"type": "object",
"required": [
"name",
"shoesizeLeft"
],
"properties": {
"name": {
"title": "Name",
"description": "Gimme yea name lad",
"type": "string",
"pattern": "^[^/]*$",
"minLength": 2
},
"invitation": {
"type": "string",
"format": "html",
"title": "Invitation Design",
"description": "Design the invitation in full technicolor HTML"
},
"favorite": {
"title": "Favorite",
"type": "string",
"enum": [
"undefined",
"null",
"NaN"
]
},
"shoesizeLeft": {
"title": "Shoe size (left)",
"default": 42,
"type": "number"
},
"shoesizeRight": {
"title": "Shoe size (right)",
"default": 42,
"type": "number"
},
"attributes": {
"type": "object",
"title": "Attributes",
"required": [
"eyecolor"
],
"properties": {
"eyecolor": {
"type": "string",
"format": "color",
"title": "Eye color",
"default": "pink"
},
"haircolor": {
"type": "string",
"title": "Hair color"
},
"shoulders": {
"type": "object",
"title": "Shoulders",
"properties": {
"left": {
"type": "string",
"title": "Left"
},
"right": {
"type": "string",
"title": "Right"
}
}
}
}
},
"things": {
"type": "array",
"title": "I like...",
"items": {
"type": "string",
"enum": [
"clowns",
"compiling",
"sleeping"
]
}
},
"dislike": {
"type": "array",
"title": "I dislike...",
"items": {
"type": "string",
"title": "I hate"
}
},
"soul": {
"title": "Terms Of Service",
"description": "I agree to sell my undying <a href='https://www.youtube.com/watch?v=dQw4w9WgXcQ'>soul</a>",
"type": "boolean",
"default": true
},
"soulserial": {
"title": "Soul Serial No",
"type": "string"
},
"date": {
"title": "Date of party",
"type": "string",
"format": "date"
},
"radio": {
"title": "Radio type",
"type": "string",
"enum": [
"Transistor",
"Tube"
]
},
"radio2": {
"title": "My Second Radio",
"type": "string",
"enum": [
"Transistor",
"Tube"
]
},
"radiobuttons": {
"type": "string",
"enum": [
"Select me!",
"No me!"
]
}
}
}`
From first glance, it seems to generate an ID on the first input field. So I presume it is related to the Key in the form and the title in the Schema.
ID fields are generated from the last segment of the key in old 0.x versions and a combined form name and object path in the next version code for 1.0.0 and beyond.
So from 1.0.0 onward you will have proper unique ids like:
formName--objectName-arrayName-4-property
While a class matching that will also be available along with a version without array positions: formName--objectName-arrayName-property
The combination of unique id and flexible classes should cater to any customisation needs.
I have some problems with calling mixes in jade.
There is fragment of my layout:
section.page-content
if blocks && blocks.content
each blockProps, blockName in blocks.content
+blockName(blockProps)
I pass these params::
"blocks": {
"content": {
"menu": {
"items": [
{
"href": "href1",
"title": "title1",
"target": "target1",
"text": "text1"
},
{
"href": "href2",
"title": "title2",
"target": "target2",
"text": "text2"
}
]
},
"catalog_structure": {
"items": [
{
"text": "i1",
"href": "i1 href",
"title": "tit"
},
{
"text": "i2",
"href": "i2 href",
"title": "tit"
},
{
"text": "i3",
"href": "i3 href",
"title": "tit",
"items": [
{
"text": "i3_1",
"href": "i3_1 href",
"title": "tit"
},
{
"text": "i3_2",
"href": "i3_2 href",
"title": "tit"
}
]
},
{
"text": "i4",
"href": "i4 href",
"title": "tit"
}
]
},
}
}
And i want to call mixin with the name "blockName".
I tryed to call it in different ways.
Please, help me with my question.
Sorry for my poor english.
It is not possible.
visionmedia confirmed a year ago "it's not currently possible no"
Reference:
https://github.com/visionmedia/jade/issues/751
I want to get some elements from json response from youtube api:
I get this response in my script:
{
"version": "1.0",
"encoding": "UTF-8",
"feed": {
"xmlns": "http://www.w3.org/2005/Atom",
"xmlns$media": "http://search.yahoo.com/mrss/",
"xmlns$openSearch": "http://a9.com/-/spec/opensearchrss/1.0/",
"xmlns$gd": "http://schemas.google.com/g/2005",
"xmlns$yt": "http://gdata.youtube.com/schemas/2007",
"id": {
"$t": "http://gdata.youtube.com/feeds/api/videos"
},
"updated": {
"$t": "2013-01-13T15:48:18.863Z"
},
"category": [
{
"scheme": "http://schemas.google.com/g/2005#kind",
"term": "http://gdata.youtube.com/schemas/2007#video"
}
],
"title": {
"$t": "Videos matching: humor",
"type": "text"
},
"logo": {
"$t": "http://www.youtube.com/img/pic_youtubelogo_123x63.gif"
},
"link": [
{
"rel": "alternate",
"type": "text/html",
"href": "http://www.youtube.com"
},
{
"rel": "http://schemas.google.com/g/2005#feed",
"type": "application/atom+xml",
"href": "http://gdata.youtube.com/feeds/api/videos"
},
{
"rel": "http://schemas.google.com/g/2005#batch",
"type": "application/atom+xml",
"href": "http://gdata.youtube.com/feeds/api/videos/batch"
},
{
"rel": "self",
"type": "application/atom+xml",
"href": "http://gdata.youtube.com/feeds/api/videos?alt=json&q=humor&start-index=1&max-results=1&lr=es&orderby=published"
},
{
"rel": "next",
"type": "application/atom+xml",
"href": "http://gdata.youtube.com/feeds/api/videos?alt=json&q=humor&start-index=2&max-results=1&lr=es&orderby=published"
}
],
"author": [
{
"name": {
"$t": "YouTube"
},
"uri": {
"$t": "http://www.youtube.com/"
}
}
],
"generator": {
"$t": "YouTube data API",
"version": "2.1",
"uri": "http://gdata.youtube.com"
},
"openSearch$totalResults": {
"$t": 10595
},
"openSearch$startIndex": {
"$t": 1
},
"openSearch$itemsPerPage": {
"$t": 1
},
"entry": [
{
"id": {
"$t": "http://gdata.youtube.com/feeds/api/videos/HAUdFeouzgM"
},
"published": {
"$t": "2013-01-13T15:43:26.000Z"
},
"updated": {
"$t": "2013-01-13T15:43:26.000Z"
},
"category": [
{
"scheme": "http://schemas.google.com/g/2005#kind",
"term": "http://gdata.youtube.com/schemas/2007#video"
},
{
"scheme": "http://gdata.youtube.com/schemas/2007/categories.cat",
"term": "Film",
"label": "Cine y animación"
}
],
"title": {
"$t": "Chica Troll en dibujo: TiparracoSA (IrukoArt)",
"type": "text"
},
"content": {
"$t": "Canal del artista creador: www.youtube.com Si quieres ver camaras ocultas dale aqui: www.youtube.com Si quieres ver a la chica troll VS pervertidos aqui: www.youtube.com Canal principal --- (Bromas con camara oculta y humor) www.youtube.com Sigueme en Twitter: twitter.com Sigueme en Facebook: www.facebook.com",
"type": "text"
},
"link": [
{
"rel": "alternate",
"type": "text/html",
"href": "http://www.youtube.com/watch?v=HAUdFeouzgM&feature=youtube_gdata"
},
{
"rel": "http://gdata.youtube.com/schemas/2007#video.responses",
"type": "application/atom+xml",
"href": "http://gdata.youtube.com/feeds/api/videos/HAUdFeouzgM/responses"
},
{
"rel": "http://gdata.youtube.com/schemas/2007#video.related",
"type": "application/atom+xml",
"href": "http://gdata.youtube.com/feeds/api/videos/HAUdFeouzgM/related"
},
{
"rel": "http://gdata.youtube.com/schemas/2007#mobile",
"type": "text/html",
"href": "http://m.youtube.com/details?v=HAUdFeouzgM"
},
{
"rel": "self",
"type": "application/atom+xml",
"href": "http://gdata.youtube.com/feeds/api/videos/HAUdFeouzgM"
}
],
"author": [
{
"name": {
"$t": "TiparracoTV"
},
"uri": {
"$t": "http://gdata.youtube.com/feeds/api/users/TiparracoTV"
}
}
],
"gd$comments": {
"gd$feedLink": {
"rel": "http://gdata.youtube.com/schemas/2007#comments",
"href": "http://gdata.youtube.com/feeds/api/videos/HAUdFeouzgM/comments",
"countHint": 0
}
},
"media$group": {
"media$category": [
{
"$t": "Film",
"label": "Cine y animación",
"scheme": "http://gdata.youtube.com/schemas/2007/categories.cat"
}
],
"media$content": [
{
"url": "http://www.youtube.com/v/HAUdFeouzgM?version=3&f=videos&app=youtube_gdata",
"type": "application/x-shockwave-flash",
"medium": "video",
"isDefault": "true",
"expression": "full",
"duration": 324,
"yt$format": 5
},
{
"url": "rtsp://v1.cache2.c.youtube.com/CiILENy73wIaGQkDzi7qFR0FHBMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp",
"type": "video/3gpp",
"medium": "video",
"expression": "full",
"duration": 324,
"yt$format": 1
},
{
"url": "rtsp://v1.cache2.c.youtube.com/CiILENy73wIaGQkDzi7qFR0FHBMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp",
"type": "video/3gpp",
"medium": "video",
"expression": "full",
"duration": 324,
"yt$format": 6
}
],
"media$description": {
"$t": "Canal del artista creador: www.youtube.com Si quieres ver camaras ocultas dale aqui: www.youtube.com Si quieres ver a la chica troll VS pervertidos aqui: www.youtube.com Canal principal --- (Bromas con camara oculta y humor) www.youtube.com Sigueme en Twitter: twitter.com Sigueme en Facebook: www.facebook.com",
"type": "plain"
},
"media$keywords": {
},
"media$player": [
{
"url": "http://www.youtube.com/watch?v=HAUdFeouzgM&feature=youtube_gdata_player"
}
],
"media$thumbnail": [
{
"url": "http://i.ytimg.com/vi/HAUdFeouzgM/0.jpg",
"height": 360,
"width": 480,
"time": "00:02:42"
},
{
"url": "http://i.ytimg.com/vi/HAUdFeouzgM/1.jpg",
"height": 90,
"width": 120,
"time": "00:01:21"
},
{
"url": "http://i.ytimg.com/vi/HAUdFeouzgM/2.jpg",
"height": 90,
"width": 120,
"time": "00:02:42"
},
{
"url": "http://i.ytimg.com/vi/HAUdFeouzgM/3.jpg",
"height": 90,
"width": 120,
"time": "00:04:03"
}
],
"media$title": {
"$t": "Chica Troll en dibujo: TiparracoSA (IrukoArt)",
"type": "plain"
},
"yt$duration": {
"seconds": "324"
}
},
"yt$statistics": {
"favoriteCount": "0",
"viewCount": "1"
}
}
]
}
}
I want to access some elements like title, tags, and link to use in my script. I eval json and i try to access to elements, but are inside arrays and another json objects i think and can't get the script work:
var datos=data.responseText;
var respuesta = eval("(" + data.responseText + ")");
alert(respuesta.entry.title);
This code don't work, how i can access to the elements?
Try alert(respuesta.entry[0].title); instead. entry is an array.
EDIT Also as we noted in the comments entry is yet one more level deeper in the json. The correct expression is actually: alert(respuesta.feed.entry[0].title);. I suggest you use Online JSON Beautifier to beutify your json and make it easier to understand.