Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2013
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Using / as String Instead of an Operator

    Hello all,

    I am trying to use the / symbol from some JSON code but it will only recognize it as an operator. After spending two hours researching this, I realized that I could really use some help. For some coding languages I know that it is the \ but I have tried that already.The last line is giving me problems:

    [CODE]
    var all_cryptsy = <?php echo file_get_contents('http://pubapi.cryptsy.com/api.php?method=marketdatav2'); ?> ;

    var amc_btc_cryptsy = all_cryptsy.return.markets.AMC\/BTC;
    [CODE]

    Also, I am trying to make it so that "return" does not act as a function, but as a string.

    I am pretty new to coding so any and all help would be greatly appreciated. Thank you guys in advance, your time is greatly appreciated.

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,280
    Thanks
    12
    Thanked 343 Times in 339 Posts
    the problem here is that neither / nor \ are allowed as (native) JS variable/property name (which is what you try). use bracket notation instead of dot notation, sou you can use strings. all_cryptsy.return.markets["AMC/BTC"];
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • Users who have thanked Dormilich for this post:

    Thorasar (12-15-2013)

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,335
    Thanks
    11
    Thanked 588 Times in 569 Posts
    there is nothing special about the url slash (/), it needs no escaping.
    simply use array syntax instead of dot syntax on the offending part of the path:

    Code:
    var amc_btc_cryptsy = all_cryptsy.return.markets['AMC/BTC'];
    edit: didn't see Dormilich's answer; is there an echo in here? (great minds think alike)
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • Users who have thanked rnd me for this post:

    Thorasar (12-15-2013)

  • #4
    New to the CF scene
    Join Date
    Dec 2013
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks for the advice guys. Your suggestions worked perfectly.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •