Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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"
    }
]


C#
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
Updated 10-May-13 3:14am
v4

1 solution

Try by removing double quote

"vehicleId" as vehicleId


[
    {
        vehicleId: "1",
        status: "Running",
        position: "x",
        battery: "25",
        distanceTravelled: "123",
        destination: "y",
        freeSeats: "2",
        speed: "32"
    }
]
 
Share this answer
 
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900