如何处理包含数字字符串的JSON

I am pulling JSON data from a webserver using the following PHP code

 $result = mysql_query("select lat,lng from gpsdata limit 10");
 $rows = array();
 while($r = mysql_fetch_assoc($result)) {
  $rows[] = $r;
 }

 print json_encode($rows);

I am using Javascript to get this data with this

 $.getJSON('returngps.php').done(function(data) {
    for (var i=0;i< data.length;i++ ){
    console.log(data[i]);
    }
  }

My issue is the data I am getting returned. The output I am currently getting is:

   {lat: "53.399793333333", lng: "-6.3844516666667"}

What I want to work with is:

   {lat: 53.399793333333, lng: -6.3844516666667}

Is there a way to convert this?

Try using parseFloat:

data[i].lat = parseFloat(data[i].lat);
data[i].lng = parseFloat(data[i].lng);

The problem is that the retrieval of the numbers from MySQL to PHP results in them being cast as strings. (I HATE that the relationship between PHP and MySQL doesn't respect type!) The JSON serialization, then, appropriately maintains the string type.

As such, you need to cast the values to floats while retrieving. This will result in the JSON serialization treating the value as a number instead of a string, and won't require any ridiculous string manipulations, or assumptions about data type, in your receiving JS.

$result = mysql_query("select lat,lng from gpsdata limit 10");
$rows = array();
while($r = mysql_fetch_assoc($result)) {
    $r['lat'] = (float) $r['lat'];
    $r['lon'] = (float) $r['lon'];

    $rows[] = $r;
}