Click here to Skip to main content
Rate this: bad
good
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 3:43am
Edited 10-May-13 4: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 at 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
0 OriginalGriff 200
1 PIEBALDconsult 150
2 BillWoodruff 148
3 Jochen Arndt 135
4 DamithSL 130
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 10 May 2013
Copyright © CodeProject, 1999-2014
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