Jump to content

JSON, I hate it.


Recommended Posts

I'm having as much trouble figuring out how JSON works as I did learning a little SQL.

I've tried 4 of the different JSON UDFs around the forums, and I'm on day 3 of trying to figure this out myself... I'm actually beginning to worry that my JSON data is bad.

I tried messing with associative arrays.
/?do=embed' frameborder='0' data-embedContent>>

An old[er]? JSON UDF:
/?do=embed#entry1111352'' frameborder='0' data-embedContent>>

A new RFC compliant one:
'?do=embed' frameborder='0' data-embedContent>>

and the "non-strict" one:

 

I'm building a Google Voice UDF for AutoIt and found out how to get JSON return values for everything I need, which I've heard is what I want.

Could someone just show me a quick example of iterating through the different JSON values?

I was able to get the RFC compliant one to spit out a little info, which had me hopeful, but still stumped.

$t = FileRead("C:\Users\Owner\Downloads\download.xml")
$test = _JSONDecodeall($t)
_ArrayDisplay($test[0])

$test1 =  _JSONDecode($t, 'messages')
$test2 =  _JSONDecode($t, 'JSON_unpack')
_ArrayDisplay($test1)
_ArrayDisplay($test2)

You can grab your own JSON examples from here.
http://google.com/voice/request/messages

If an old or trusted member, MVP, or that bum trancexx, needs my JSON output, I'll PM it.  o:)  :whistle: 
 

Edited by BinaryBrother

SIGNATURE_0X800007D NOT FOUND

Link to comment
Share on other sites

If I want to get swf player location from the downloaded file I run this:

#include "JSMN.au3"
    
$sPlayer = Jsmn_ObjGet(Jsmn_Decode(FileRead("C:\Users\Owner\Downloads\download.xml")), "swfPlayer")
    
ConsoleWrite($sPlayer & @CRLF)
... and get:

/voice/resources/532502447-audioPlayer.swf
Is that wrong? Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Thanks for your helpful reply, trancexx.
 

Using your example, I get the same output as you. However, when I try to get "messages", "messageList", "id", or anything else, it just returns blank. I'm so lost in this JSON abyss.

Edit:
I just discovered a resource that, I believe, will greatly help me in this project. It has allowed me to visualize JSON data and its structure.

Resource: http://jsonviewer.stack.hu/

Edited by BinaryBrother

SIGNATURE_0X800007D NOT FOUND

Link to comment
Share on other sites

Ultimately, I'm trying to access the actual message text and relevant information, ex; Who texted me and from which number. That information is in the JSON data.

I believe I am after the array of information inside "messageList".
http://screencast.com/t/LQlwFbIYJ

$test = Jsmn_Decode(FileRead("C:\Users\Owner\Downloads\messages"))
$sPlayer = Jsmn_ObjGet($test, "messageList")
_ArrayDisplay($sPlayer)

This gives me an empty $array[5], but it is correctly sized to fit the data.  :doh: 

I'm a lot closer now, though. I wasn't getting any values, before.

Edited by BinaryBrother

SIGNATURE_0X800007D NOT FOUND

Link to comment
Share on other sites

trancexx has provided me everything that I need for figuring out the rest. As soon as I'm done with this UDF, I'll post it in the examples section.

Many thanks, trancexx.

Of course, it didn't help when most other JSON documentation says that JSON key/value pairs are normally accessed like,

$Array = $JSON.MessagesArray
$Var = $Object.Username

Or

$Username = $JSON.Key("Username")

But the method seems to be a bit different with AutoIt.

Edited by BinaryBrother

SIGNATURE_0X800007D NOT FOUND

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...