SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot virginiamonkeys's Avatar
    Join Date
    Jun 2003
    Location
    Stafford, Virginia, USA
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Proper JSON format

    I'm not sure which forum this belongs in - PHP or JavaScript, or either.

    But, I have a php JSON script and it's returning the following JSON format to me:

    {"success":true,"fillData":[[{"fieldName":"price01","fieldValue":"60.0000"},{"fieldName":"description01","fieldValue":"Pinellas Park, FL"},{"fieldName":"travel-time01","fieldValue":"0.2000"},{"fieldName":"time-on-site01","fieldValue":"0.1333"},{"fieldName":"time-at-shop01","fieldValue":"0.0500"}]]}object(Services_JSON)#1 (1) { ["use"]=> int(0) }
    I'm getting an error in my program that the JSON format is bad, so I pasted that JSON code into the JSON Validator here: http://www.jsonlint.com/

    I get the following message:

    syntax error, unexpected TINVALID, expecting $end at line 27
    Parsing failed
    It parses like this:

    PHP Code:
    {
        
    "success"true,
        
    "fillData": [
            [
                {
                    
    "fieldName""price01",
                    
    "fieldValue""60.0000"
                
    },
                {
                    
    "fieldName""description01",
                    
    "fieldValue""Pinellas Park, FL"
                
    },
                {
                    
    "fieldName""travel-time01",
                    
    "fieldValue""0.2000"
                
    },
                {
                    
    "fieldName""time-on-site01",
                    
    "fieldValue""0.1333"
                
    },
                {
                    
    "fieldName""time-at-shop01",
                    
    "fieldValue""0.0500"
                
    }
            ]
        ]
    }
    object(Services_JSON)#1 (1) {
        
    [
            
    "use"
        
    ]=> int(0

    I don't know exactly what is going wrong with this format. Do you?

  2. #2
    SitePoint Zealot virginiamonkeys's Avatar
    Join Date
    Jun 2003
    Location
    Stafford, Virginia, USA
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh... and line 27 would be this one:

    }object(Services_JSON)#1 (1) {

  3. #3
    SitePoint Member
    Join Date
    Oct 2005
    Location
    Silicon Valley
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How are you generating the JSON? Typically I do it with json_encode().

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe you have a stray var_dump()

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,789
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Perhaps it needs a ; between } and object and that #1 doesn't make sense

    }; object(Services_JSON) (1) {
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

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