Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 22nd, 2024, 9:20 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: JSON
PostPosted: February 28th, 2012, 5:13 pm 
Offline

Joined: May 25th, 2008, 4:57 pm
Posts: 355
Location: Ireland
Opus: Pro 9.75
OS: Windows 10
System: MacBook Pro (Intel 2020)
Has anyone been able to pull data from online into Opus using JSON? I want to parse it so I can get it as an object and sort through the data. The eval() method isn't working for me, I wanted to use something similar to:
Code:
var p = eval("(" + contact + ")");


I can manually parse it line by line, but this isn't ideal.



Thanks

_________________
Opus Pro 9.75 on MacBookPro (2020 Intel) running Parallels 19 with Windows 10 (x64)


For this message lmc has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: JSON
PostPosted: February 28th, 2012, 7:21 pm 
Offline

Joined: May 25th, 2008, 4:57 pm
Posts: 355
Location: Ireland
Opus: Pro 9.75
OS: Windows 10
System: MacBook Pro (Intel 2020)
Or how would people recommend for pulling information in from the web and reading into Opus arrays for further manipulation?

Thanks.

_________________
Opus Pro 9.75 on MacBookPro (2020 Intel) running Parallels 19 with Windows 10 (x64)


For this message lmc has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: JSON
PostPosted: February 28th, 2012, 7:23 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
InternetPostData

Mack

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Re: JSON
PostPosted: February 29th, 2012, 10:02 am 
Offline

Joined: May 25th, 2008, 4:57 pm
Posts: 355
Location: Ireland
Opus: Pro 9.75
OS: Windows 10
System: MacBook Pro (Intel 2020)
Hi Mack,

Oh yeah I can pull the JSON into a string using InternetPostData.

But I want to parse that string, I have written a function that manually goes through the string to parse.

Is there anyway to do the following, using something similar to jQuery, I tried to eval() method of parsing but it doesn't seem to work. This is javascript using jQuery library so won't work in OpusScript either.

Code:
var obj = jQuery.parseJSON('{"name":"John"}');
alert( obj.name === "John" );


But showing example of what I want to do.

_________________
Opus Pro 9.75 on MacBookPro (2020 Intel) running Parallels 19 with Windows 10 (x64)


For this message lmc has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: JSON
PostPosted: February 29th, 2012, 10:07 am 
Offline

Joined: May 25th, 2008, 4:57 pm
Posts: 355
Location: Ireland
Opus: Pro 9.75
OS: Windows 10
System: MacBook Pro (Intel 2020)
This is the data that is parsed with JSON and I'm feeding into OpusScript using InternetPostData.

Quote:
[{"UpdateId":1,"DateUpdated":"2/7/2012","IsFree":0,"PageName":"Page_Name_1","PageTitle":"Page Title","Ilm":"david_pub_00000001.ilm","Image":"Imagehere.jpg","Link":"http://"},{"UpdateId":2,"DateUpdated":"2/16/2012","IsFree":0,"PageName":"Test_Update_Page_1","PageTitle":"Test Update","Ilm":"david_pub_00000002.ilm","Image":"Imagehere.jpg","Link":"http://"},{"UpdateId":3,"DateUpdated":"2/14/2012","IsFree":1,"PageName":"Proper Working Update","PageTitle":"This is the page title","Ilm":"david_pub_00000005.ilm","Image":"Imagehere.jpg","Link":"http://"},{"UpdateId":5,"DateUpdated":"2/16/2012","IsFree":0,"PageName":"Iceland_Pack_1","PageTitle":"Why Iceland Rules","Ilm":"david_pub_00000004.ilm","Image":"iceland.jpg","Link":"http://"}]



I can pull this into a string, and then manually parse it into arrays using, see code - first revision still messy, but works.


Code:
function ParseJSON()
{
//WebVar is the JSON string pulled from online
Debug.trace("WebVar " + WebVar + "\n\n");

//CHECKS FOR [ ] AND REMOVES THEM
WebVar = WebVar.split("[").join("")
WebVar = WebVar.split("]").join("")

var CloudUpdateList = WebVar.split("},");

   for (i = 0; i < CloudUpdateList.length; i++)
   {
   CloudUpdateList[i] = CloudUpdateList[i].split("}").join("");
   CloudUpdateList[i] = CloudUpdateList[i].split("{").join("");
   
   Debug.trace("Line " + i + " " + CloudUpdateList[i] + "\n" );
   
   var MakeMoreArrays = "CloudUpdateListSplit" + i +" = new Array()";
   eval(MakeMoreArrays);
   Debug.trace("MakeMoreArrays " + MakeMoreArrays + "\n");
   
   var SplitMakeMoreArrays = "CloudUpdateListSplit" + i + " = CloudUpdateList[" + i + "].split(\",\")";
   eval(SplitMakeMoreArrays);
   Debug.trace("SplitMakeMoreArrays " + SplitMakeMoreArrays + "\n");
   
   }

Debug.trace("*************************\n" );



for (p = 0; p < CloudUpdateList.length; p++)
{
   for (i = 0; i < CloudUpdateListSplit1.length; i++)
   {
   var EvalWebVarIndex = "CloudUpdateListSplit" + p + "[" + i + "] = CloudUpdateListSplit" + p + "[" + i + "]" + ".substring(CloudUpdateListSplit" + p + "[" + i + "].indexOf(\":\")+1)"
   //Debug.trace("EvalWebVarIndex: " + EvalWebVarIndex + "\n" + "\n");
   eval(EvalWebVarIndex);
   
   Debug.trace("\n\n")
   Debug.trace("CloudUpdateListSplit0 [" + i + "] " + CloudUpdateListSplit0[i] + "\n")
   Debug.trace("CloudUpdateListSplit1 [" + i + "] " + CloudUpdateListSplit1[i] + "\n")
   Debug.trace("CloudUpdateListSplit2 [" + i + "] " + CloudUpdateListSplit2[i] + "\n")
   Debug.trace("CloudUpdateListSplit3 [" + i + "] " + CloudUpdateListSplit3[i] + "\n")
   }
}

Debug.trace("*************************\n" );
}

_________________
Opus Pro 9.75 on MacBookPro (2020 Intel) running Parallels 19 with Windows 10 (x64)


For this message lmc has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: JSON
PostPosted: February 29th, 2012, 10:48 am 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Hi LMC,

JSON uses object literals which, if memory serves, weren't introduced until version 1.2 of JavaScript and therefore not part of OpusScript. As for jQuery (brilliant idea), but even if we could use includes, the code in jQuery will be way more advanced that OpusScript supports :-( :-!

You have a choice to either return the string in a format supported by Opus' InternetPostData and have this build an object or basically extract from the string as you have already been doing.

Mack

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


For this message mackavi has been thanked by : lmc


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 29 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 © 2000, 2002, 2005, 2007 phpBB Group