Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5980935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:52:19+00:00 2026-05-22T21:52:19+00:00

I have this array which is retrieved by a json_encode().When I execute $.getJSON(‘beta.php’ ,

  • 0

I have this array which is retrieved by a json_encode().When I execute

$.getJSON('beta.php' , function(data){
    console.log(data);
});

I get the result as follows

[
Object { StuId="1", fName="Saman", more...},
Object { StuId="2", fName="Marry", more...},
Object { StuId="3", fName="Navjoth", more...},
Object { StuId="4", fName="Jassu", more...}
]

I’m trying to iterate through this result using

$.each(data, function(key, value){

            for(var key in value){

                if(value.hasOwnProperty(key)){                  

                        $("#article tbody").html(                       
                        "<tr><td>" + value.StuId + 
                        "</td><td>" + value.fName + 
                        "</td><td>" + value.lName +
                        "</td><td>" + value.age +
                        "</td><td>" + value.grade + 
                        "</td></tr>");

                        $("article tbody").appendTo("document.body");               

                }

                }

        });

.I guess It is impossible because of the above format of the array.

If someone could explain why this is happening and how to correct it I would be really grateful.I want to know how to convert the above into the following format.

[
{"StuId":"1","fName":"Saman","lName":"Kumara","age":"14","grade":"A"},
{"StuId":"2","fName":"Marry","lName":"Vass","age":"12","grade":"B"},
{"StuId":"3","fName":"Navjoth","lName":"Bogal","age":"32","grade":"A"},
{"StuId":"4","fName":"Jassu","lName":"Singh","age":"22","grade":"E"}
]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:52:20+00:00Added an answer on May 22, 2026 at 9:52 pm

    You are overwriting the tables html with different values each time.

    $(document).ready(function() {
      var html = "";
      var data = [
              { StuId:"1", fName:"Saman"},
              { StuId:"2", fName:"Marry"},
              { StuId:"3", fName:"Navjoth"},
              { StuId:"4", fName:"Jassu"}
              ]
      $.each(data, function(key, value){
        console.log(value + "--" + key);
        html += "<div><span>" + value.StuId + "</span><span>" + value.fName + "</span></div>";
      });
      $('body').html(html)
    });
    

    Loops in JavaScript are different from other languages. You need closures.

    Have a look here:

    http://www.mennovanslooten.nl/blog/post/62

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php script to retrieve data from a MysQL databse following an
I have the following code which retrieves data with a JSON request: // Replace
I have an accordion which contains a repeater. That repeater takes an array as
To begin with, I have a database that holds map data for a game
I am working on an application which works with GPS data. Part of the
I have some JSON of which the following is a small sample: { results:
UPDATE I am still debugging this issue and still have not found a solution.
I have some code which retrieves user comments from my database: $comments = mysql_query(SELECT
Scenario- I have a method that returns an object retrieved from an NSMutableArray similar
I'm doing a simple ajax query which retrieves a variable-length list of values as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.