Your Universal Remote Control Center
RemoteCentral.com
Philips Pronto Professional Forum - View Post
Up level
Up level
The following page was printed from RemoteCentral.com:

Login:
Pass:
 
 

Original thread:
Post 20 made on Saturday September 5, 2020 at 11:05
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,636
Fischi,

You could go here:

[Link: github.com]

Get this file and make a Prontoscript library called json2.js (add the necessary @title, @version, @author comments to the top of it). The file, with comments is like 18KB. If you strip out the comments you can cut down the size and load time on the Pronto tremendously. In fact, I have the original version but the one I use is an optimized one that I ran through the Google Closure compiler.


What will require some further research is whether the above library will fully support the Date markup above noted as:

"\/Date(1599204401437+0200)\/"

It does appear in the markup that the value above is wrapped in quotes which means it will be parsed as a string. If you need to get the real date, it will require a bit of coding to recreate it. It looks as if it is the number or seconds or milliseconds since Jan 01, 1970 with a +2 hour offset from UTC.

Next, you have "YR Wetter für Pronto link Text". A second research topic.

Because of these characters which are above ASCII position 127, the entire string may need to be UTF-8 decoded prior to executing Parse. There are various UTF-8 decoders in pure javascript that you could create a library from as well.



Then once adding the library to your Activity you could simply do.

var obj = JSON.parse(responseText);
var myValue = obj.Devices[0].value;

Again, this is my opinion but the above 2 lines are much more readable than the string munging that was suggested in the previous post.

Finally, if you need to send a request, simply build it as an object and 'stringify' it.

var myRequest = {foo:"one",bar:2};
// using a TCP socket as an example of a transport.
mySocket.write(JSON.stringify(myRequest));

Last edited by Lyndel McGee on September 5, 2020 11:22.
Lyndel McGee
Philips Pronto Addict/Beta Tester


Hosting Services by ipHouse