[SOLVED] How do I simplify return value using Regex?

Get help using Construct 2

Post » Wed Jun 25, 2014 11:35 am

Hello, I've used Imgur API and it worked, the problem is it returns data with all parameters, it looks like:


Code: Select all
{"data":{"id":"TjJuJ29","title":null,"description":null,"datetime":1403695169,"type":"image\/png","animated":false,"width":1538,"height":839,"size":733684,"views":0,"bandwidth":0,"favorite":false,"nsfw":null,"section":null,"deletehash":"lCqsN0tKqWyJFET","link":"http:\/\/i.imgur.com\/TjJuJ29.jpg"},"success":true,"status":200}



I need to know how to use Regex to convert it into simple Link URL and forget every parameters.

Parameter of URL is "link":"http:\/\/i.imgur.com\/TjJuJ29.jpg"


Thanks!
Last edited by Joannesalfa on Wed Jun 25, 2014 3:44 pm, edited 1 time in total.
B
99
S
35
G
29
Posts: 3,139
Reputation: 28,421

Post » Wed Jun 25, 2014 1:21 pm

I noticed it's JSON, it's not possible with Regex.

Isn't there a way to use parse to get a link?
B
99
S
35
G
29
Posts: 3,139
Reputation: 28,421

Post » Wed Jun 25, 2014 1:31 pm

you could load that json string into an array and just call the value of the url.
B
44
S
10
G
8
Posts: 437
Reputation: 6,463

Post » Wed Jun 25, 2014 1:32 pm

The data is what matters, you could try to isolate it, then get rid of the { }, then a good use a loops and tokens could make it so you put each data as key and values of dictionnary, then you could just retrieve the value you want
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Wed Jun 25, 2014 1:47 pm

It's irrelevant that it's JSON. RegEx parses text. You have text.
ImageImageImage
B
71
S
22
G
241
Posts: 3,734
Reputation: 134,494

Post » Wed Jun 25, 2014 1:58 pm

@Ubivis , @Aphrodite I'm sorry, I'm not expert about backend, I had no clue how to get each JSON property in array or dicctionary, would you explain me how to do it?

@blackhornet Can you help me?
B
99
S
35
G
29
Posts: 3,139
Reputation: 28,421

Post » Wed Jun 25, 2014 2:53 pm

You'll need some error code, but this works:

JSON={"data":{"id":"TjJuJ29","title":null,"description":null,"datetime":1403695169,"type":"image\/png","animated":false,"width":1538,"height":839,"size":733684,"views":0,"bandwidth":0,"favorite":false,"nsfw":null,"section":null,"deletehash":"lCqsN0tKqWyJFET","link":"http:\/\/i.imgur.com\/TjJuJ29.jpg"},"success":true,"status":200}

Key = "link":"(http:.*)"}

RegexMathAt(JSON, Key, 1)
ImageImageImage
B
71
S
22
G
241
Posts: 3,734
Reputation: 134,494

Post » Wed Jun 25, 2014 3:45 pm

@blackhornet I got another workaround, I used this plugin plugin-json-import-export-generate-edit-inspect_t100042 to inspect this JSON and I made ugly hack to get rid of other parameters and got proper return as URL.

Your snippet is saved on my disk for future reference, thank you!
B
99
S
35
G
29
Posts: 3,139
Reputation: 28,421

Post » Wed Jun 25, 2014 5:43 pm

You could try parsing the json with the browser object. For example,
System set some_variable to
Browser.ExecJS("(function(){var obj = {""url"":""some_link"", ""other"":""something_else""} return obj.url})();")
B
11
S
2
G
1
Posts: 202
Reputation: 1,580


Return to How do I....?

Who is online

Users browsing this forum: Artcadev and 46 guests