Click here to Skip to main content
13,149,756 members (57,159 online)
Rate this:
 
Please Sign up or sign in to vote.
Hello, I'm having problems while getting JSPN from PHP, shown below:

[{
        "vehicleId": "1",
        "status": "Running",
        "position": "x",
        "battery": "25",
        "distanceTravelled": "123",
        "destination": "y",
        "freeSeats": "2",
        "speed": "32"
    }
]


But, my new version of my code it is comes like that (without quotes in number values) and it gives a parse Json error and it doen't shown anything.
 
[{
 
        "vehicleId": 1,
        "status": "Running",
        "position": "x",
        "battery": 25,
        "distanceTravelled": 123,
        "destination": "y",
        "freeSeats": 2,
        "speed": 32
    }
]



I checked the format at jsonlint.com and it is valid. The error in log in Eclipse is:


05-09 21:37:25.536: E/Web Console(336): SyntaxError: Unable to parse JSON string at file:///android_asset/www/MobileMan.js:37
 
        34  xmlhttp.open("GET",url,false);
        35  xmlhttp.send();
        36  var json = xmlhttp.responseText; 
        37  obj = JSON.parse(json);


I also tried the Javascript code in my computer on Chrome and everything works fine. I couldn't resolve the problem. Thanks for your answers.
Posted 10-May-13 2:43am
Updated 10-May-13 3:14am
v4

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Try by removing double quote

"vehicleId" as vehicleId


[
    {
        vehicleId: "1",
        status: "Running",
        position: "x",
        battery: "25",
        distanceTravelled: "123",
        destination: "y",
        freeSeats: "2",
        speed: "32"
    }
]
  Permalink  
Comments
fatihkok 10-May-13 9:20am
   
hello @Prasad C.M, I' m Sorry I just forgot to add " part while I'm writing the question in here, I editted my question. My original code it is ok but it doesn't work again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web04 | 2.8.170924.2 | Last Updated 10 May 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100