Jump to content

Recommended Posts

Hi I really want to thank everyone helping me with my posts I have learned so much from this forum last couple of weeks . I have almost made my httprequest script 100% functional , but to ease the coding further I need some sort of Json parser making the data usable here is what I mean: 

 

data returned in console log:

{"success":true,"url":"\/","user_id":*******}<script>window.top.location.href ="/start/index?action=token_login&token=dPYoUKg_iUxCDa8";</script>

 

I guess someone already made something to convert this string into readable data ?  I found an old post regarding Json and tried this without luck: 

I need to extract the login token any suggestion ? 

 

 

 

 

 

Share this post


Link to post
Share on other sites

thanks for the link Dan , was looking at this one earlier , maybe better to do with a clear head in the morning :) 

Share this post


Link to post
Share on other sites

@nine In this case yes , later I guess I need everything , do you mind giving an example how I could extract the login_token  dPYoUKg_iUxCDa8

Share this post


Link to post
Share on other sites

here :

#include <Constants.au3>

$text = '{"success":true,"url":"\/","user_id":*******}<script>window.top.location.href ="/start/index?action=token_login&token=dPYoUKg_iUxCDa8";</script>'

MsgBox ($MB_SYSTEMMODAL,"",StringRegExp ($text, '&token=(.*)";', $STR_REGEXPARRAYMATCH )[0])

 

Share this post


Link to post
Share on other sites

Nice thanks, this StringRegExp is like magic for me , lol Worked like a charm however It did add this to the string >21:49:08 how can that be removed ?

Share this post


Link to post
Share on other sites
Posted (edited)
8 minutes ago, Acce said:

It did add this to the string +>21:49:08 how can that be removed ?

Local $sString = "text... +>21:49:08 text..."
ConsoleWrite($sString & @CRLF)
$sString = StringReplace ("text... +>21:49:08 text...", "+>21:49:08", "")
ConsoleWrite($sString & @CRLF)

 

Edited by Musashi

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Share this post


Link to post
Share on other sites
Posted (edited)

Maybe this would better work :

#include <Constants.au3>

$text = '{"success":true,"url":"\/","user_id":*******}<script>window.top.location.href ="/start/index?action=token_login&token=dPYoUKg_iUxCDa8";</script>'

MsgBox ($MB_SYSTEMMODAL,"",StringRegExp ($text, '&token=([0-9a-zA-Z_]*)', $STR_REGEXPARRAYMATCH )[0])

Anyway there is always a solution with SRE, you just need to invest more time in this feature...

Edit : I just realized that you did a ConsoleWrite without @CRLF at the end (instead of MsgBox), that's why you were getting those additional characters.

Edited by Nine

Share this post


Link to post
Share on other sites

What you suggested works very well., but now I really need to read and work with all the Json data , do you guys mind showing how I can use the json udf to read the json data ? 

 

I got a huge response from the server all in json format. Have tried a few different thing with no luck so far 

Share this post


Link to post
Share on other sites

Show us what you have tried so far, so we get a base to work on.  Provide also the response from the server.  Take a look at  JsonDump(). 

Share this post


Link to post
Share on other sites

Hi thanks for looking into this ,  I tried a couple of different things not working well any of it, Here is the server response 

   {"User_ID":"User65789","Servers":{"en13":0},"Servers":[{"id":"en1","num_id":1,"name":"Arvahall","started_at":1332972000,"register":true,"login":true,"best":false,"premium_world":false,"rank":1,"update":null,"constraint_worlds":"","description":"","user_limit":120000},{"id":"en2","num_id":2,"name":"Brisgard","started_at":1334613600,"register":true,"login":true,"best":false,"premium_world":false,"rank":2,"update":null,"constraint_worlds":"","description":"","user_limit":120000},{"id":"en3","num_id":3,"name":"Cirgard","started_at":1338415200,"register":true,"login":true,"best":false,"premium_world":false,"rank":3,"update":null,"constraint_worlds":"","description":"","user_limit":120000},{"id":"en4","num_id":4,"name":"Dinegu","started_at":1340748000,"register":true,"login":true,"best":false,"premium_world":false,"rank":4,"update":null,"constraint_worlds":"","description":"","user_limit":120000},{"id":"en5","num_id":5,"name":"East-Nagach","started_at":1342389600,"register":true,"login":true,"best":false,"premium_world":false,"rank":5,"update":null,"constraint_worlds":"","description":" ","user_limit":120000},{"id":"en6","num_id":6,"name":"Fel Dranghyr","started_at":1345068000,"register":true,"login":true,"best":false,"premium_world":false,"rank":6,"update":null,"constraint_worlds":"","description":"","user_limit":120000},{"id":"en7","num_id":7,"name":"Greifental","started_at":1346191200,"register":true,"login":true,"best":false,"premium_world":false,"rank":7,"update":null,"constraint_worlds":"","description":"","user_limit":120000},{"id":"en8","num_id":8,"name":"Houndsmoor","started_at":1358290800,"register":true,"login":true,"best":false,"premium_world":false,"rank":8,"update":null,"constraint_worlds":"","description":"","user_limit":120000},{"id":"en9","num_id":9,"name":"Jaims","started_at":1405288800,"register":true,"login":true,"best":false,"premium_world":false,"rank":9,"update":null,"constraint_worlds":"","description":"","user_limit":120000},{"id":"en10","num_id":10,"name":"Korch","started_at":1412767260,"register":true,"login":true,"best":true,"premium_world":false,"rank":10,"update":null,"constraint_worlds":"","description":"","user_limit":120000},{"id":"en11","num_id":11,"name":"Langendorn","started_at":1422961200,"register":true,"login":true,"best":false,"premium_world":false,"rank":11,"update":null,"constraint_worlds":"","description":"","user_limit":120000},{"id":"en12","num_id":12,"name":"Mount Killmore","started_at":1426507860,"register":true,"login":true,"best":false,"premium_world":false,"rank":12,"update":null,"constraint_worlds":"","description":"","user_limit":120000},{"id":"en13","num_id":13,"name":"Noarsil","started_at":1428486180,"register":true,"login":true,"best":false,"premium_world":false,"rank":13,"update":null,"constraint_worlds":"","description":"","user_limit":120000},{"id":"en14","num_id":14,"name":"Odhrorvar","started_at":1430737200,"register":true,"login":true,"best":false,"premium_world":false,"rank":14,"update":null,"constraint_worlds":"","description":"","user_limit":120000},{"id":"en15","num_id":15,"name":"Parkog","started_at":1520253600,"register":true,"login":true,"best":false,"premium_world":false,"rank":15,"update":null,"constraint_worlds":"","description":"","user_limit":120000},{"id":"en16","num_id":16,"name":"Rugnir","started_at":1520505180,"register":true,"login":true,"best":false,"premium_world":false,"rank":16,"update":null,"constraint_worlds":"","description":"","user_limit":120000},{"id":"en17","num_id":17,"name":"Sinerania","started_at":1571144400,"register":true,"login":true,"best":false,"premium_world":false,"rank":17,"update":null,"constraint_worlds":"","description":"","user_limit":120000}]}

 

It works very well inserting it into json parser online.

 

 

Share this post


Link to post
Share on other sites

Not sure why you are having issues. Maybe it would be more obvious if you actually showed us some code. :rolleyes:

FWIW, this simple example works fine for me --

#include <JSON.au3> ; https://www.autoitscript.com/forum/topic/148114-a-non-strict-json-udf-jsmn

Local $sJSON = '{"User_ID":"User65789","Servers":{"en13":0},"Servers":[{"id":"en1","num_id":1,"name":"Arvahall","started_at":1332972000,"register":true,"login":true,"best":false,"premium_world":false,"rank":1,"update":null,"constraint_worlds":"","description":"","user_limit":120000},{"id":"en2","num_id":2,"name":"Brisgard","started_at":1334613600,"register":true,"login":true,"best":false,"premium_world":false,"rank":2,"update":null,"constraint_worlds":"","description":"","user_limit":120000},{"id":"en3","num_id":3,"name":"Cirgard","started_at":1338415200,"register":true,"login":true,"best":false,"premium_world":false,"rank":3,"update":null,"constraint_worlds":"","description":"","user_limit":120000},{"id":"en4","num_id":4,"name":"Dinegu","started_at":1340748000,"register":true,"login":true,"best":false,"premium_world":false,"rank":4,"update":null,"constraint_worlds":"","description":"","user_limit":120000},{"id":"en5","num_id":5,"name":"East-Nagach","started_at":1342389600,"register":true,"login":true,"best":false,"premium_world":false,"rank":5,"update":null,"constraint_worlds":"","description":" ","user_limit":120000},{"id":"en6","num_id":6,"name":"Fel Dranghyr","started_at":1345068000,"register":true,"login":true,"best":false,"premium_world":false,"rank":6,"update":null,"constraint_worlds":"","description":"","user_limit":120000},{"id":"en7","num_id":7,"name":"Greifental","started_at":1346191200,"register":true,"login":true,"best":false,"premium_world":false,"rank":7,"update":null,"constraint_worlds":"","description":"","user_limit":120000},{"id":"en8","num_id":8,"name":"Houndsmoor","started_at":1358290800,"register":true,"login":true,"best":false,"premium_world":false,"rank":8,"update":null,"constraint_worlds":"","description":"","user_limit":120000},{"id":"en9","num_id":9,"name":"Jaims","started_at":1405288800,"register":true,"login":true,"best":false,"premium_world":false,"rank":9,"update":null,"constraint_worlds":"","description":"","user_limit":120000},{"id":"en10","num_id":10,"name":"Korch","started_at":1412767260,"register":true,"login":true,"best":true,"premium_world":false,"rank":10,"update":null,"constraint_worlds":"","description":"","user_limit":120000},{"id":"en11","num_id":11,"name":"Langendorn","started_at":1422961200,"register":true,"login":true,"best":false,"premium_world":false,"rank":11,"update":null,"constraint_worlds":"","description":"","user_limit":120000},{"id":"en12","num_id":12,"name":"Mount Killmore","started_at":1426507860,"register":true,"login":true,"best":false,"premium_world":false,"rank":12,"update":null,"constraint_worlds":"","description":"","user_limit":120000},{"id":"en13","num_id":13,"name":"Noarsil","started_at":1428486180,"register":true,"login":true,"best":false,"premium_world":false,"rank":13,"update":null,"constraint_worlds":"","description":"","user_limit":120000},{"id":"en14","num_id":14,"name":"Odhrorvar","started_at":1430737200,"register":true,"login":true,"best":false,"premium_world":false,"rank":14,"update":null,"constraint_worlds":"","description":"","user_limit":120000},{"id":"en15","num_id":15,"name":"Parkog","started_at":1520253600,"register":true,"login":true,"best":false,"premium_world":false,"rank":15,"update":null,"constraint_worlds":"","description":"","user_limit":120000},{"id":"en16","num_id":16,"name":"Rugnir","started_at":1520505180,"register":true,"login":true,"best":false,"premium_world":false,"rank":16,"update":null,"constraint_worlds":"","description":"","user_limit":120000},{"id":"en17","num_id":17,"name":"Sinerania","started_at":1571144400,"register":true,"login":true,"best":false,"premium_world":false,"rank":17,"update":null,"constraint_worlds":"","description":"","user_limit":120000}]}'
Json_Dump($sJSON)

Local $oJSON = Json_Decode($sJSON)
ConsoleWrite(".Servers[1].name = " & Json_Get($oJSON, ".Servers[1].name") & @CRLF)

 

Share this post


Link to post
Share on other sites

It worked like magic I was starting to worry I had to make something myself. think my mistake was not having this part of the code earlier :

Json_Dump($sJSON)

 

Thanks alot for your help 

Share this post


Link to post
Share on other sites
32 minutes ago, Acce said:

think my mistake was not having this part of the code earlier :


Json_Dump($sJSON)

Nope... that's not required. All it does is dump the details to the Scite console showing you how to access the individual elements

18 minutes ago, Acce said:

But how can I get it to return this data 


Servers":{"en13":0}

See my answer above. 😀 Check the Scite console and find the entry that will give you the results you desire.

Share this post


Link to post
Share on other sites

hmmm. I see i did many thing wrong with this in the past , thanks  a bunch for all your help . So far i managed to get everything returned in console expect that pesky little line. the dump code returns it like so .Servers.en13  =0

 

Have tried this:

ConsoleWrite("Servers: " & Json_Get($oJSON, " .Servers.en13") & @CRLF)
    ConsoleWrite("Servers: " & Json_Get($oJSON, " .Servers") & @CRLF)

Its a little strange cause I get the username retunred like so:

Json_Get($oJSON, ".User_ID") & @CRLF)

 

 

 

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...