Acce Posted August 6, 2020 Share Posted August 6, 2020 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 ? Link to comment Share on other sites More sharing options...
Danp2 Posted August 6, 2020 Share Posted August 6, 2020 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Acce Posted August 6, 2020 Author Share Posted August 6, 2020 thanks for the link Dan , was looking at this one earlier , maybe better to do with a clear head in the morning Link to comment Share on other sites More sharing options...
Nine Posted August 6, 2020 Share Posted August 6, 2020 If you only need a small part of the response, you could also use StringRegExp to extract the portion you need. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Acce Posted August 6, 2020 Author Share Posted August 6, 2020 @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 Link to comment Share on other sites More sharing options...
Nine Posted August 6, 2020 Share Posted August 6, 2020 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]) “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Acce Posted August 6, 2020 Author Share Posted August 6, 2020 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 ? Link to comment Share on other sites More sharing options...
Acce Posted August 6, 2020 Author Share Posted August 6, 2020 actually this was added: +>21:49:08 Link to comment Share on other sites More sharing options...
Acce Posted August 6, 2020 Author Share Posted August 6, 2020 Never mind that was the end of my script Link to comment Share on other sites More sharing options...
Musashi Posted August 6, 2020 Share Posted August 6, 2020 (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 August 6, 2020 by Musashi "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Nine Posted August 6, 2020 Share Posted August 6, 2020 (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 August 7, 2020 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Acce Posted August 8, 2020 Author Share Posted August 8, 2020 Yeah my comment regarding the time was rather silly Link to comment Share on other sites More sharing options...
Acce Posted August 8, 2020 Author Share Posted August 8, 2020 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 Link to comment Share on other sites More sharing options...
Nine Posted August 8, 2020 Share Posted August 8, 2020 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(). Danp2 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Acce Posted August 9, 2020 Author Share Posted August 9, 2020 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. Link to comment Share on other sites More sharing options...
Danp2 Posted August 9, 2020 Share Posted August 9, 2020 Not sure why you are having issues. Maybe it would be more obvious if you actually showed us some code. 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) Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Acce Posted August 9, 2020 Author Share Posted August 9, 2020 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 Link to comment Share on other sites More sharing options...
Acce Posted August 9, 2020 Author Share Posted August 9, 2020 But how can I get it to return this data Servers":{"en13":0} Link to comment Share on other sites More sharing options...
Danp2 Posted August 9, 2020 Share Posted August 9, 2020 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. TheXman and Musashi 2 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Acce Posted August 9, 2020 Author Share Posted August 9, 2020 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) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now