XWidgetSoft Forum https://www.bbs.xwidget.com/ |
|
Json https://www.bbs.xwidget.com/viewtopic.php?f=8&t=3094 |
Page 1 of 1 |
Author: | Creator [ May 17th, 2013, 10:13 pm ] |
Post subject: | Json |
I have an array in Json how to bring one of its values in the label |
Author: | digigamer [ May 18th, 2013, 5:49 pm ] |
Post subject: | Re: Json |
Code: var array = JSON.parse("your json string here"); //use your elements var obj1 = array[0]; // // WRITE YOUR CODE HERE // Note: this code ONLY works in W7 and above... If you wish to support lower versions of windows then add the following code at the head of your script file: Code: if(!this.JSON) // check for non-existence of JSON object/functions
{ //<define a JSON object> //from https://github.com/douglascrockford/JSON-js/blob/master/json2.js //download the file and append the contents here //run the code as usual } //some code accessing json |
Author: | Creator [ May 23rd, 2013, 3:43 pm ] |
Post subject: | Re: Json |
Something I error knocks. Here at this link is JSON: http://api.vkontakte.ru/method/users.ge ... =photo_200, status Spars and need to display text ->> in Lable. need to display A reference to the awatar ->> component "picture" Please Help me |
Author: | digigamer [ May 23rd, 2013, 5:26 pm ] |
Post subject: | Re: Json |
This should be the code... what are you using can you provide something Code: //get the json.. lets say that is stored in a obj var obj = JSON.Parse("string that you receive"); var uid = obj.response[0].uid; var firstName = obj.response[0].first_name; var lastName = obj.response[0].last_name; var avatar = obj.response[0].photo_200; Here comes the bottleneck, I don't know how to set the image from a remote source. There's a thread for this but I don't remember which. Search a bit. |
Author: | Creator [ May 24th, 2013, 9:59 pm ] |
Post subject: | Re: Json |
And how to get a JSON string? In the PHP there is a function file_get_contents. Example in PHP: Code: $request = 'http://api.vkontakte.ru/method/users.get?uids=ID&fields=photo_200,status'; $response = file_get_contents($request); $info = array_shift(json_decode($response)->response); var_dump($info->photo_200); // URL photo var_dump($info->status); // status If it is not difficult to throw off the project |
Author: | digigamer [ May 25th, 2013, 11:30 pm ] |
Post subject: | Re: Json |
Definitely not but I wont advice to dump your creation. Use gethttpstr or ActiveX do fetch strings |
Author: | Creator [ May 31st, 2013, 9:37 pm ] |
Post subject: | Re: Json |
function file_get_contents_async( url ,callback) { var req = null; try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { try { req = new XMLHttpRequest(); } catch(e) {} } } if (req == null) throw new Error('XMLHttpRequest not supported'); req.open("GET",url,true); req.onreadystatechange=function() { if (req.readyState==4) { var response = req.responseText; callback(response); }}; req.send(null); } file_get_contents_async('http://api.vkontakte.ru/method/users.get?uids=1&fields=photo_200',function(response) { //get the json.. lets say that is stored in a obj //response is the downloaded string... //BE WARNED THAT : if download fails no call is made alert(response); }); var obj = (How to insert here response????????????); var uid = obj.response[0].uid; var firstName = obj.response[0].first_name; var lastName = obj.response[0].last_name; var avatar = obj.response[0].photo_200; alert(lastName); |
Author: | digigamer [ June 1st, 2013, 5:26 pm ] |
Post subject: | Re: Json |
Code: function file_get_contents_async( url ,callback) { var req = null; try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { try { req = new XMLHttpRequest(); } catch(e) {} } } if (req == null) throw new Error('XMLHttpRequest not supported'); req.open("GET",url,true); req.onreadystatechange=function() { if (req.readyState==4) { var response = req.responseText; callback(response); }}; req.send(null); } file_get_contents_async('http://api.vkontakte.ru/method/users.get?uids=1&fields=photo_200',function(response) { //get the json.. lets say that is stored in a obj //response is the downloaded string... //BE WARNED THAT : if download fails no call is made alert(response); var obj = JSON.Parse(response);; var uid = obj.response[0].uid; var firstName = obj.response[0].first_name; var lastName = obj.response[0].last_name; var avatar = obj.response[0].photo_200; alert(lastName); }); Do all coding between the brackets. |
Author: | Creator [ June 1st, 2013, 10:02 pm ] |
Post subject: | Re: Json |
I probably already tired but... response.0 null or not object: Code: function file_get_contents_async( url ,callback) { var req = null; try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { try { req = new XMLHttpRequest(); } catch(e) {} } } if (req == null) throw new Error('XMLHttpRequest not supported'); req.open("GET",url,true); req.onreadystatechange=function() { if (req.readyState==4) { var response = req.responseText; callback(response); }}; req.send(null); } function text1OnClick(Sender) { file_get_contents_async('http://api.vkontakte.ru/method/users.get?uids=1&fields=photo_200',function(response) { //get the json.. lets say that is stored in a obj //response is the downloaded string... //BE WARNED THAT : if download fails no call is made alert(response); var obj = (response); var uid = obj.response[0].uid; var firstName = obj.response[0].first_name; var lastName = obj.response[0].last_name; var avatar = obj.response[0].photo_200; alert(lastName); }); } Definitions not JSON : Code: function file_get_contents_async( url ,callback) {
var req = null; try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { try { req = new XMLHttpRequest(); } catch(e) {} } } if (req == null) throw new Error('XMLHttpRequest not supported'); req.open("GET",url,true); req.onreadystatechange=function() { if (req.readyState==4) { var response = req.responseText; callback(response); }}; req.send(null); } function text1OnClick(Sender) { file_get_contents_async('http://api.vkontakte.ru/method/users.get?uids=1&fields=photo_200',function(response) { //get the json.. lets say that is stored in a obj //response is the downloaded string... //BE WARNED THAT : if download fails no call is made alert(response); var obj = JSON.parse(response); var uid = obj.response[0].uid; var firstName = obj.response[0].first_name; var lastName = obj.response[0].last_name; var avatar = obj.response[0].photo_200; alert(lastName); }); } |
Author: | digigamer [ June 2nd, 2013, 12:58 am ] |
Post subject: | Re: Json |
Your JSON source is api.vkontakte.ru?? Then wait a min... i'm seeing what it does |
Author: | Creator [ June 4th, 2013, 12:46 am ] |
Post subject: | Re: Json |
The problem remains ... the answer comes but does not parse out |
Author: | digigamer [ June 4th, 2013, 10:50 pm ] |
Post subject: | Re: Json |
JSON not defined?? This is because the script framework is not updated. Use this widget, I've tested, it works. Attachment:
|
Page 1 of 1 | All times are UTC - 8 hours |
Powered by phpBB® Forum Software © phpBB Group http://www.phpbb.com/ |