XWidgetSoft Forum

XWidget & XLaunchpad , Desktop customization
It is currently May 10th, 2025, 10:11 am

All times are UTC - 8 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Json
PostPosted: May 17th, 2013, 10:13 pm 
Offline

Joined: March 14th, 2013, 5:49 am
Posts: 52
I have an array in Json how to bring one of its values ​​in the label


Top
 Profile  
 
 Post subject: Re: Json
PostPosted: May 18th, 2013, 5:49 pm 
Offline
User avatar

Joined: March 8th, 2013, 10:27 pm
Posts: 353
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

_________________
Life is a myriad game... Just play it!


Top
 Profile  
 
 Post subject: Re: Json
PostPosted: May 23rd, 2013, 3:43 pm 
Offline

Joined: March 14th, 2013, 5:49 am
Posts: 52
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


Top
 Profile  
 
 Post subject: Re: Json
PostPosted: May 23rd, 2013, 5:26 pm 
Offline
User avatar

Joined: March 8th, 2013, 10:27 pm
Posts: 353
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.

_________________
Life is a myriad game... Just play it!


Top
 Profile  
 
 Post subject: Re: Json
PostPosted: May 24th, 2013, 9:59 pm 
Offline

Joined: March 14th, 2013, 5:49 am
Posts: 52
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


Top
 Profile  
 
 Post subject: Re: Json
PostPosted: May 25th, 2013, 11:30 pm 
Offline
User avatar

Joined: March 8th, 2013, 10:27 pm
Posts: 353
Definitely not but I wont advice to dump your creation.
Use gethttpstr or ActiveX do fetch strings

_________________
Life is a myriad game... Just play it!


Top
 Profile  
 
 Post subject: Re: Json
PostPosted: May 31st, 2013, 9:37 pm 
Offline

Joined: March 14th, 2013, 5:49 am
Posts: 52
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);


Top
 Profile  
 
 Post subject: Re: Json
PostPosted: June 1st, 2013, 5:26 pm 
Offline
User avatar

Joined: March 8th, 2013, 10:27 pm
Posts: 353
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.

_________________
Life is a myriad game... Just play it!


Top
 Profile  
 
 Post subject: Re: Json
PostPosted: June 1st, 2013, 10:02 pm 
Offline

Joined: March 14th, 2013, 5:49 am
Posts: 52
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);
 });

}


Top
 Profile  
 
 Post subject: Re: Json
PostPosted: June 2nd, 2013, 12:58 am 
Offline
User avatar

Joined: March 8th, 2013, 10:27 pm
Posts: 353
Your JSON source is api.vkontakte.ru?? Then wait a min... i'm seeing what it does

_________________
Life is a myriad game... Just play it!


Top
 Profile  
 
 Post subject: Re: Json
PostPosted: June 4th, 2013, 12:46 am 
Offline

Joined: March 14th, 2013, 5:49 am
Posts: 52
The problem remains ... the answer comes but does not parse out


Top
 Profile  
 
 Post subject: Re: Json
PostPosted: June 4th, 2013, 10:50 pm 
Offline
User avatar

Joined: March 8th, 2013, 10:27 pm
Posts: 353
JSON not defined?? This is because the script framework is not updated.

Use this widget, I've tested, it works.
Attachment:
untitled2(2).XWidgetPkg [11.96 KiB]
Downloaded 356 times

_________________
Life is a myriad game... Just play it!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: Google [Bot] and 20 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron

Powered by phpBB® Forum Software © phpBB Group