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

0 favourites
  • 9 posts
From the Asset Store
Game "Little Dino Adventure Returns" with complete Source-Code (Construct3 / .c3p) + HTML5 Exported.
  • Hello, I've used Imgur API and it worked, the problem is it returns data with all parameters, it looks like:

    {"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}[/code:355a9t6s]
    
    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!
  • I noticed it's JSON, it's not possible with Regex.

    Isn't there a way to use parse to get a link?

  • you could load that json string into an array and just call the value of the url.

  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • It's irrelevant that it's JSON. RegEx parses text. You have text.

  • 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?

  • 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)

  • blackhornet I got another workaround, I used this plugin 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!

  • 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})();")

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)