Skip to main content
Formatting
Source Link
Wayne
  • 60.5k
  • 15
  • 135
  • 129

Need help parsing this object into JSON  (javascript)

I am trying to parse the JSON data  (at the bottom) using the JSON.parseJSON.parse method in javascript. Below is the code.

 var i;
 var myData={};
 $(document).ready(function(){
    
        $.get("http://localhost:4567/get/233307/loc/15000/10", function(data){
                display(data);
            
            }, "json");
    });
 function display(x){
    for(i = 0; i <= x.length;i++){
        myData = JSON.parse(x[i]);
    }
    alert(myData[2].uid);
 }
    

The code above, according to me should parse the JSON data and store to myDatamyData. But the alert give whichthat should have given me 233307233307 gives me an 'undefined'undefined. I feel like I'm doing everything right. Any help? Thanks.

{"id":64567868968,"uid":233307,"lat":41.418972,"long":-72.8941315,"date":"2010-11-11T16:01:15-05:00"},{"id":64567803255,"uid":
233307,"lat":41.4189505,"long":-72.89411,"date":"2010-11-11T16:00:13-05:00"},{"id":64567803254,"uid":233307,"lat":
41.4189451666667,"long":-72.8940725,"date":"2010-11-11T15:59:11-05:00"},{"id":64567803253,"uid":233307,"lat":
41.4188646666667,"long":-72.8940831666667,"date":"2010-11-11T15:58:08-05:00"},{"id":64567803252,"uid":233307,"lat":
41.4190095,"long":-72.8941905,"date":"2010-11-11T15:57:06-05:00"},{"id":64567700284,"uid":233307,"lat":
41.418972,"long":-72.894169,"date":"2010-11-11T15:56:04-05:00"}

Need help parsing this object into JSON(javascript)

I am trying to parse the JSON data(at the bottom) using the JSON.parse method in javascript. Below is the code.

 var i;
 var myData={};
 $(document).ready(function(){
    
        $.get("http://localhost:4567/get/233307/loc/15000/10", function(data){
                display(data);
            
            }, "json");
    });
 function display(x){
    for(i = 0; i <= x.length;i++){
        myData = JSON.parse(x[i]);
    }
    alert(myData[2].uid);
 }
    

The code above, according to me should parse the JSON data and store to myData. But the alert give which should have given me 233307 gives me an 'undefined'. I feel like I'm doing everything right. Any help? Thanks.

{"id":64567868968,"uid":233307,"lat":41.418972,"long":-72.8941315,"date":"2010-11-11T16:01:15-05:00"},{"id":64567803255,"uid":
233307,"lat":41.4189505,"long":-72.89411,"date":"2010-11-11T16:00:13-05:00"},{"id":64567803254,"uid":233307,"lat":
41.4189451666667,"long":-72.8940725,"date":"2010-11-11T15:59:11-05:00"},{"id":64567803253,"uid":233307,"lat":
41.4188646666667,"long":-72.8940831666667,"date":"2010-11-11T15:58:08-05:00"},{"id":64567803252,"uid":233307,"lat":
41.4190095,"long":-72.8941905,"date":"2010-11-11T15:57:06-05:00"},{"id":64567700284,"uid":233307,"lat":
41.418972,"long":-72.894169,"date":"2010-11-11T15:56:04-05:00"}

Need help parsing this object into JSON  (javascript)

I am trying to parse the JSON data  (at the bottom) using the JSON.parse method in javascript. Below is the code.

 var i;
 var myData={};
 $(document).ready(function(){
    
        $.get("http://localhost:4567/get/233307/loc/15000/10", function(data){
                display(data);
            
            }, "json");
    });
 function display(x){
    for(i = 0; i <= x.length;i++){
        myData = JSON.parse(x[i]);
    }
    alert(myData[2].uid);
 }
    

The code above, according to me should parse the JSON data and store to myData. But the alert that should have given me 233307 gives me an undefined. I feel like I'm doing everything right. Any help? Thanks.

{"id":64567868968,"uid":233307,"lat":41.418972,"long":-72.8941315,"date":"2010-11-11T16:01:15-05:00"},{"id":64567803255,"uid":
233307,"lat":41.4189505,"long":-72.89411,"date":"2010-11-11T16:00:13-05:00"},{"id":64567803254,"uid":233307,"lat":
41.4189451666667,"long":-72.8940725,"date":"2010-11-11T15:59:11-05:00"},{"id":64567803253,"uid":233307,"lat":
41.4188646666667,"long":-72.8940831666667,"date":"2010-11-11T15:58:08-05:00"},{"id":64567803252,"uid":233307,"lat":
41.4190095,"long":-72.8941905,"date":"2010-11-11T15:57:06-05:00"},{"id":64567700284,"uid":233307,"lat":
41.418972,"long":-72.894169,"date":"2010-11-11T15:56:04-05:00"}
Source Link
Jebish
  • 25
  • 1
  • 3

Need help parsing this object into JSON(javascript)

I am trying to parse the JSON data(at the bottom) using the JSON.parse method in javascript. Below is the code.

 var i;
 var myData={};
 $(document).ready(function(){
    
        $.get("http://localhost:4567/get/233307/loc/15000/10", function(data){
                display(data);
            
            }, "json");
    });
 function display(x){
    for(i = 0; i <= x.length;i++){
        myData = JSON.parse(x[i]);
    }
    alert(myData[2].uid);
 }
    

The code above, according to me should parse the JSON data and store to myData. But the alert give which should have given me 233307 gives me an 'undefined'. I feel like I'm doing everything right. Any help? Thanks.

{"id":64567868968,"uid":233307,"lat":41.418972,"long":-72.8941315,"date":"2010-11-11T16:01:15-05:00"},{"id":64567803255,"uid":
233307,"lat":41.4189505,"long":-72.89411,"date":"2010-11-11T16:00:13-05:00"},{"id":64567803254,"uid":233307,"lat":
41.4189451666667,"long":-72.8940725,"date":"2010-11-11T15:59:11-05:00"},{"id":64567803253,"uid":233307,"lat":
41.4188646666667,"long":-72.8940831666667,"date":"2010-11-11T15:58:08-05:00"},{"id":64567803252,"uid":233307,"lat":
41.4190095,"long":-72.8941905,"date":"2010-11-11T15:57:06-05:00"},{"id":64567700284,"uid":233307,"lat":
41.418972,"long":-72.894169,"date":"2010-11-11T15:56:04-05:00"}