Sencha touch 2, printing nested JSON array using xtemplate - sencha-touch-2

I am developing a simple movie listing app.
I am using rotten tomatoes api. following is the json :
movies": [{
"id": "771310572",
"title": "Cloud Atlas",
"year": 2012,
"mpaa_rating": "R",
"runtime": 163,
"release_dates": {
"theater": "2012-10-26"
},
"ratings": {
"critics_rating": "Fresh",
"critics_score": 80,
"audience_score": 98
},
"synopsis": "Cloud Atlas explores how the actions and consequences of individual lives impact one another throughout the past, the present and the future. Action, mystery and romance weave dramatically through the story as one soul is shaped from a killer into a hero and a single act of kindness ripples across centuries to inspire a revolution in the distant future. Each member of the ensemble appears in multiple roles as the stories move through time. -- (C) Warner Bros.",
"posters": {
"thumbnail": "http://content6.flixster.com/movie/11/16/71/11167192_mob.jpg",
"profile": "http://content6.flixster.com/movie/11/16/71/11167192_pro.jpg",
"detailed": "http://content6.flixster.com/movie/11/16/71/11167192_det.jpg",
"original": "http://content6.flixster.com/movie/11/16/71/11167192_ori.jpg"
},
"abridged_cast": [{
"name": "Tom Hanks",
"id": "162655641",
"characters": ["Dermot 'Duster' Hoggins", "Dr. Henry Goose", "Isaac Sachs", "Valleysman Zachry"]
}, {
"name": "Halle Berry",
"id": "162652386",
"characters": ["Jocasta Ayrs", "Luisa Rey", "Meronym"]
}, {
"name": "Jim Broadbent",
"id": "162653369",
"characters": ["Vyvyan Ayrs"]
}, {
"name": "Hugo Weaving",
"id": "162709905",
"characters": ["Bill Smoke", "Nurse Noakes", "Old Georgie"]
}, {
"name": "Jim Sturgess",
"id": "563717190",
"characters": ["Adam Ewing", "Hae-Joo Im"]
}]
I am able to get the first list view showing the list of movies and ontap on movie list item, I am able to load the next view to show the movie details.
I am stuck in displaying abridged_cast in the xtemplate. if I use {abridged_cast} the page displays object, Object.
I am unable to find any functions which will extract the values from this array and display.
How to display the array content in the template?
Thanks.

Related

How to Get Twitch Video Thumbnail URL?

Video-sharing websites such as Youtube has a endpoint for video thumbnails
Example: http://img.youtube.com/vi/youtube_id/default.jpg
where youtube_id = the id of the video
So I can just do
<img src="http://img.youtube.com/vi/youtube_id/default.jpg">
with no problem
Does twitch have something like this as well?
Update 2018
Twitch requires you to use its API so you can get access to video thumbnails. Apparently, this is because the URL of the thumbnails may change
Here is a simple guide how to get access to a twitch video thumbnail
You have to get access to Twitch dev API - to do this you need to register an account at https://glass.twitch.tv
After registering an account you must then create an App from your twitch dev dashboard
After creating the App, you will be given a Client ID to be used for that app - note that the app is the one which will be using the twitch API (for example, your website)
You can now pass the client_id as a query string parameter to https://api.twitch.tv/kraken/videos/106400740?client_id=xxxxxxx where 106400740 is the video id (note that 'kraken' here is constant - not sure of the origin behind its name) - note that the request will return a JSON object which contains an error message if you do not include a client_id
The request will return a JSON object which looks something like:
{
"title": "Door 5 vs Tilted Gamers",
"description": "COOL Games: Killing Spree first match # Mineski. Grove, Los Ba\u00f1os",
"description_html": "COOL Games: Killing Spree first match # Mineski. Grove, Los Ba\u00f1os<br>",
"broadcast_id": 1,
"broadcast_type": "upload",
"status": "recorded",
"language": "en",
"tag_list": "",
"views": 4,
"created_at": "2017-11-08T03:13:12Z",
"published_at": "2017-11-08T04:33:37Z",
"url": "https:\/\/www.twitch.tv\/videos\/188543310",
"_id": "v188543310",
"recorded_at": "2017-11-08T03:13:12Z",
"game": "Dota 2",
"length": 2436,
"preview": "https:\/\/static-cdn.jtvnw.net\/s3_vods\/esportsdotcool\/188543310\/3534ab8c-bf7d-4c8a-b502-c406825bf75f\/thumb\/index-0000000000-320x240.jpg",
"animated_preview_url": "https:\/\/vod-storyboards.twitch.tv\/esportsdotcool\/188543310\/3534ab8c-bf7d-4c8a-b502-c406825bf75f\/storyboards\/188543310-strip-0.jpg",
"thumbnails": [
{
"type": "generated",
"url": "https:\/\/static-cdn.jtvnw.net\/s3_vods\/esportsdotcool\/188543310\/3534ab8c-bf7d-4c8a-b502-c406825bf75f\/thumb\/index-0000000000-320x240.jpg"
},
{
"type": "generated",
"url": "https:\/\/static-cdn.jtvnw.net\/s3_vods\/esportsdotcool\/188543310\/3534ab8c-bf7d-4c8a-b502-c406825bf75f\/thumb\/index-0000000006-320x240.jpg"
},
{
"type": "generated",
"url": "https:\/\/static-cdn.jtvnw.net\/s3_vods\/esportsdotcool\/188543310\/3534ab8c-bf7d-4c8a-b502-c406825bf75f\/thumb\/index-0000000012-320x240.jpg"
},
{
"type": "generated",
"url": "https:\/\/static-cdn.jtvnw.net\/s3_vods\/esportsdotcool\/188543310\/3534ab8c-bf7d-4c8a-b502-c406825bf75f\/thumb\/index-0000000018-320x240.jpg"
}
],
"fps": {
"144p30": 29.999544341896,
"360p30": 29.999544341896,
"480p30": 29.999544341896
},
"resolutions": {
"144p30": "256x144",
"360p30": "640x360",
"480p30": "852x480"
},
"channel": {
"name": "esportsdotcool",
"display_name": "esportsdotcool"
},
"_links": {
"self": "https:\/\/api.twitch.tv\/kraken\/videos\/v188543310",
"channel": "https:\/\/api.twitch.tv\/kraken\/channels\/esportsdotcool"
}
}
Under the thumbnails array you can find the url to the video.
PS: As you can see, the thumbnails array has length of 4 - at this point I think this is because of the different sizes of the image that the author of the video can put up

HERE Places API: not all items have PVID

I'm using HERE Places API.
Firstly I'm doing a search.
For Example this query :
https://places.cit.api.here.com/places/v1/discover/search?q=Test&at=35.6111,-97.5467&r=500&size=1&app_id=DemoAppId01082013GAL&app_code=AJKnXv84fjrb0KIHawS0Tg&show_refs=pvid&pretty
According to this documentation (Link) If I add show_refs=pvid to query string, in result I will get external id which I can use to query lookup endpoint.
But in result I get next response :
{
"results": {
"next": "https://places.cit.api.here.com/places/v1/discover/search;context=Zmxvdy1pZD1hY2ExNzk3NC0zYzg3LTU5NzQtYmZkMC04YjAzMDZlYWIzMWJfMTUwNjA3NjMzMTYyMl83NDY3XzM4NTAmb2Zmc2V0PTEmc2l6ZT0x?at=35.6111%2C-97.5467&q=Test&app_id=DemoAppId01082013GAL&app_code=AJKnXv84fjrb0KIHawS0Tg",
"items": [
{
"position": [
35.60369,
-97.51761
],
"distance": 2756,
"title": "Southwest Test & Balance",
"averageRating": 0,
"category": {
"id": "business-services",
"title": "Business & Services",
"href": "https://places.cit.api.here.com/places/v1/categories/places/business-services?app_id=DemoAppId01082013GAL&app_code=AJKnXv84fjrb0KIHawS0Tg",
"type": "urn:nlp-types:category",
"system": "places"
},
"icon": "https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/02.icon",
"vicinity": "200 NW 132nd St<br/>Oklahoma City, OK 73114",
"having": [],
"type": "urn:nlp-types:place",
"href": "https://places.cit.api.here.com/places/v1/places/8403fv6k-d1b2fde0616e0326e321a54b88cd9f53;context=Zmxvdy1pZD1hY2ExNzk3NC0zYzg3LTU5NzQtYmZkMC04YjAzMDZlYWIzMWJfMTUwNjA3NjMzMTYyMl83NDY3XzM4NTAmcmFuaz0w?app_id=DemoAppId01082013GAL&app_code=AJKnXv84fjrb0KIHawS0Tg",
"id": "8403fv6k-d1b2fde0616e0326e321a54b88cd9f53",
"authoritative": true
}
]
},
"search": {
"context": {
"location": {
"position": [
35.6111,
-97.5467
],
"address": {
"text": "Oklahoma City, OK 73134<br/>USA",
"postalCode": "73134",
"city": "Oklahoma City",
"county": "Oklahoma",
"stateCode": "OK",
"country": "United States",
"countryCode": "USA"
}
},
"type": "urn:nlp-types:place",
"href": "https://places.cit.api.here.com/places/v1/places/loc-dmVyc2lvbj0xO3RpdGxlPU9rbGFob21hK0NpdHk7bGF0PTM1LjYxMTE7bG9uPS05Ny41NDY3O2NpdHk9T2tsYWhvbWErQ2l0eTtwb3N0YWxDb2RlPTczMTM0O2NvdW50cnk9VVNBO3N0YXRlQ29kZT1PSztjb3VudHk9T2tsYWhvbWE7Y2F0ZWdvcnlJZD1jaXR5LXRvd24tdmlsbGFnZTtzb3VyY2VTeXN0ZW09aW50ZXJuYWw;context=c2VhcmNoQ29udGV4dD0x?app_id=DemoAppId01082013GAL&app_code=AJKnXv84fjrb0KIHawS0Tg"
}
}
}
In response no object references
Is it a bug or not every place has this external id?
I am responding as member of the team around HERE Places API.
Yes, not every place has a pvid. That is why I would suggest using the Sharing Id instead. I realize that the documentation should be improved to clarify that.
The Sharing Ids can be obtained by adding show_refs=sharing to either your search query or a place details request. It can be found in the field references. Once you have the sharing id you can you the lookup endpoint as you intended.
Take a look at:
https://places.cit.api.here.com/places/v1/places/8403fv6k-d1b2fde0616e0326e321a54b88cd9f53;context=Zmxvdy1pZD00YWU2ZWZjNi01ZjgzLTUwYTQtOTI4OS0xZjliMGMwNWY3NjBfMTUwNzA0NDE0OTc3NV84MTI5XzU1NDcmcmFuaz0w?app_id=DemoAppId01082013GAL&app_code=AJKnXv84fjrb0KIHawS0Tg&show_refs=pvid
and
https://places.cit.api.here.com/places/v1/places/8409q8yy-6af3c3e50bcb4f859686797b2be5773d;context=Zmxvdy1pZD00YWU2ZWZjNi01ZjgzLTUwYTQtOTI4OS0xZjliMGMwNWY3NjBfMTUwNzA0NDE0OTc3NV84MTI5XzU1NDcmcmFuaz0w?app_id=DemoAppId01082013GAL&app_code=AJKnXv84fjrb0KIHawS0Tg&show_refs=pvid
On those two examples, the only difference is the placeId.
In the docs, there's not a single reference saying that the external identifier is required or existant for every place.
Since it represents an external identifier, I believe we could assume that it's not required.
And it's what we just saw with your place (8403fv6k-d1b2fde0616e0326e321a54b88cd9f53): this one don't have any external identifier.
Based on your comments, what you need is the information about a place.
So, after you run your first query, you should get something like:
{
title: "Southwest Test & Balance",
position: [],
id: "8403fv6k-d1b2fde0616e0326e321a54b88cd9f53",
href: "https://[...]"
}
With this ID, you could access it:
places.cit.api.here.com/places/v1/places/8403fv6k-d1b2fde0616e0326e321a54b88cd9f53;context=Zmxvdy1pZD0zYTFlZjg5ZS02ZTY5LTUxYmEtYWFkYS1kY2UwZWMyNDdkMDBfMTUwNzEzNjUxNjI5N182NjExXzc2OTgmcmFuaz0w?app_id=DemoAppId01082013GAL&app_code=AJKnXv84fjrb0KIHawS0Tg
Or directly using the href information.
This response already is giving you the ID and URL to access all the info of a single place.
You don't need any other external ID or reference.

Deserializing JSON in Visual basic

I want to deserialize this string, it is from a rest api, but i dont know how to do it.
i know i have to create a class with the struture of the string, and i have to run the command with deserialize.
Can anyone help me?
Thanks
"
{
"success": true,
"data": {
"categories": {
"17": [
{
"category_id": "17",
"name": "Software",
"description": "",
"sort_order": "4",
"meta_title": "",
"meta_description": "",
"meta_keyword": "",
"language_id": "1",
"image": "http://newapi3.opencart-api.com/image/cache/catalog/categories/12316636179756542373092288841575795860377n-100x100.jpg",
"categories": null
},
{
"category_id": "17",
"name": "Software",
"description": "",
"sort_order": "4",
"meta_title": "",
"meta_description": "",
"meta_keyword": "",
"language_id": "2",
"image": "http://newapi3.opencart-api.com/image/cache/catalog/categories/12316636179756542373092288841575795860377n-100x100.jpg",
"categories": null
}
],
"18": [
{
"category_id": "18",
"name": "Laptops & Notebooks",
"description": "<p>\r\n\tShop Laptop feature only the best laptop deals on the market. By comparing laptop deals from the likes of PC World, Comet, Dixons, The Link and Carphone Warehouse, Shop Laptop has the most comprehensive selection of laptops on the internet. At Shop Laptop, we pride ourselves on offering customers the very best laptop deals. From refurbished laptops to netbooks, Shop Laptop ensures that every laptop - in every colour, style, size and technical spec - is featured on the site at the lowest possible price.</p>\r\n",
"sort_order": "2",
"meta_title": "",
"meta_description": "",
"meta_keyword": "",
"language_id": "1",
"image": "http://newapi3.opencart-api.com/image/cache/catalog/demo/hp_2-100x100.jpg",
"categories": null
},
{
"category_id": "18",
"name": "Laptops & Notebooks",
"description": "<p>\r\n\tShop Laptop feature only the best laptop deals on the market. By comparing laptop deals from the likes of PC World, Comet, Dixons, The Link and Carphone Warehouse, Shop Laptop has the most comprehensive selection of laptops on the internet. At Shop Laptop, we pride ourselves on offering customers the very best laptop deals. From refurbished laptops to netbooks, Shop Laptop ensures that every laptop - in every colour, style, size and technical spec - is featured on the site at the lowest possible price.</p>\r\n",
"sort_order": "2",
"meta_title": "",
"meta_description": "",
"meta_keyword": "",
"language_id": "2",
"image": "http://newapi3.opencart-api.com/image/cache/catalog/demo/hp_2-100x100.jpg",
"categories": null
}
]
}
}
}"
Use this service to generate classes from JSON strings. It will save you a lot of time (and headache).
After that, you might consider using a third-party library for deserializing the JSON string. You have quite a few options but the most popular and the best according to me, is JSON.NET.
After you have installed it, you can go forward and access whatever data you want after deserializing the JSON.
Example:
Dim data = JsonConvert.DeserializeObject(Of YourDataClass)("<YourJSONString>");
If data.Success Then
Console.WriteLine(data.Data.Categories(0).Name);
End If

is there a wikipedia api call that can retrieve restriction status of the article?

Otherwise I must do querySelector on the page content to find if there is a some kind of padlock and by try and error check what (id or class) is unique to that icon.
Other source to find is this info is to go on information page by adding $action=info to the url params. But then another problem comes in that the protection status is written in that's particular wiki language.
Using the API is the right way to do it, but you need to use action=query. The padlocks icons are inconsistent across wikis, and most wikis probably don't even have them.
If you use the right parameters for your API query, you should be getting the results you're looking for.
Example for the English Wikipedia:
https://en.wikipedia.org/w/api.php?action=query&prop=info&format=json&inprop=protection&titles=Elton%20John gives you this result:
{
"batchcomplete": "",
"query": {
"pages": {
"5052197": {
"pageid": 5052197,
"ns": 0,
"title": "Elton John",
"contentmodel": "wikitext",
"pagelanguage": "en",
"touched": "2015-10-02T03:49:24Z",
"lastrevid": 683730854,
"length": 115931,
"protection": [
{
"type": "edit",
"level": "autoconfirmed",
"expiry": "infinity"
},
{
"type": "move",
"level": "sysop",
"expiry": "infinity"
}
],
"restrictiontypes": [
"edit",
"move"
]
}
}
}
}
Here the protection array tells you that only sysops can move the page, and only autoconfirmed users can edit it.
If you make a similar query on another wiki, say the French Wikipedia: https://fr.wikipedia.org/w/api.php?action=query&prop=info&format=json&inprop=protection&titles=Malia%20Obama , you get this in response (trimmed):
"protection": [
{
"type": "edit",
"level": "sysop",
"expiry": "infinity"
},
{
"type": "move",
"level": "sysop",
"expiry": "infinity"
}
],
"restrictiontypes": [
"edit",
"move"
]
In this case, sysops are the only one who can move and edit the page.

Xbmc Database Path

I am working with XBMC. I have installed XBMC in my system(Windows 7, 32 bit). Xbmc is working fine in my system. I have developed an application in order to control the Xbmc remotely from Ipad. In order to retrieve the music files or video files from Xbmc, I am unable to. By searching the forums of xbmc, I found that we can write an sql query to get them out. But, the thing is I am unable to make out where the database is located in my system. Someone help me out where I can find it.
Regards,
Sushma.
The database itself
By default the location of the database is that described on the wiki page XBMC databases
but the actual location can be changed by the user, or a different database technology can be used entirely.
The settings that would affect this are located in advancedsettings.xml.
But in general it is advised by the XBMC developers to never access the database directly.
JSONRPC
In order to help with interacting with the database XBMC has supported the JSONRPC queries, the one downside of these is that XBMC needs to be running at the time to respond to these queries. The major advantage is that it XBMC will find the database for you and expose access to it with a common interface.
JSONRPC support was first added to XBMC in "Darhma" (v10), became really useful in "Eden" (v11) and will support almost everything possible in "Frodo" (v12). Information about the use of JSONRPC can be found in the wiki.
An example
In this example I'm assuming that you are targeting "Eden", the current stable release of XBMC. Also I have formatted the following with new lines, these are not required and are not present in the response from XBMC.
Request
If you were to use JSONRPC the request you would need to send would look something like:
{
"jsonrpc": "2.0",
"method": "VideoLibrary.GetMovies",
"params": {
"properties": [
"title",
"year",
"file"
],
"limits": {
"start": 0,
"end": 2
}
},
"id": 1
}
Note: If you wanted different information about each movie you could use other properties listed here.
*Note: You probably want to omit the "limits" part to get all movies.*
Responce
The response to this would be something like:
{
"id": 1,
"jsonrpc": "2.0",
"result": {
"limits": {
"end": 2,
"start": 0,
"total": 47
},
"movies": [
{
"label": "Label for movie",
"movieid": 1,
"title": "Title of movie",
"year": 2012
},
{
"label": "Label for another movie",
"movieid": 2,
"title": "Title of another movie",
"year": 2010
},
{
"label": "Label for a third movie",
"movieid": 3,
"title": "Title of a third movie",
"year": 2012
}
]
}
}
What to do now?
You have a choice at this point, you can either:
Add "file" to the list of properties, this will return the "file" property, the location of the video file.
Use JSONRPC to tell xbmc to play a movie.
Using this method is best when you don't want to play the file locally (on the iPad) but instead on XBMC.
Playing a movie on XBMC via JSONRPC
This is quite simple, use the "movieid" you received earlier in the following request:
{
"jsonrpc": "2.0",
"method": "Player.Open",
"params": {
"item": {
"movieid": 2
}
},
"id": 1
}
Lastly I would note that there are equivalent commands for TV episodes as shown for movies.