How to parse JavaScript part in HTML source?

Discussion in 'iOS Programming' started by mikezang, Dec 24, 2012.

  1. mikezang macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #1
    I have a html source as below, how can I parse it easily? can I use JSON to it?
    please give some suggestion, thanks a lot!
    Code:
    <script>
    _c=[
    [{'1','program1],['2','program2'],['4','program3'],['5','program4'],['6','program5'],['7','program6'],['8','program7'],['9','program8'],['12','program9'}],
    [{'1','program1],['2','program2'],['4','program3'],['5','program4'],['6','program5'],['7','program6'],['8','program7'],['9','program8'],['12','program9'}],
    [{'1','program1],['2','program2'],['4','program3'],['5','program4'],['6','program5'],['7','program6'],['8','program7'],['9','program8'],['12','program9'}]
    ]
    </script>
    
     
  2. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #2
    What is it you want to do?

    What have you tried?

    Does this actually belong in the iOS programming section?
     
  3. mikezang thread starter macrumors 6502a

    Joined:
    May 22, 2010
    Location:
    Tokyo, Japan
    #3
    I use NSURLConnection to download a html source, there are code as above, I want to know if there is a easy way to parse it
     
  4. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
    The posted JavaScript is invalid. It's missing at least one closing quote, and it uses { ) with unnamed values.

    Please fix the posted code, or post an actual example from the real HTML.


    If you look at the JSON spec, you will see that single quotes (which your example uses) are invalid for JSON. So you can't parse the example posted by using a JSON parser, even if you fixed the problems I listed above. You could translate single-quotes to double-quotes, but without knowing the actual content of the elements, you might be creating another problem.
     

Share This Page