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

  • SEARCH
  • Home
  • 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 7035863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:21:17+00:00 2026-05-28T01:21:17+00:00

I’m interperting a json string into a variable using jquery’s parseJSON() function. The problem

  • 0

I’m interperting a json string into a variable using jquery’s parseJSON() function. The problem is, it’s turning my data into an object instead of a 2d array. Eg,

myData = $.parse(JSON(data));
myData.name// = "Bob"

The problem is, “name” is not supposed to be a key (assuming that is the correct term). Instead, it should be:

myData[0] // = "name"
myData[1] // = "Bob"

How would I convert this? Or is there a different method than using a for loop to walk through the index of an array (but still be able to access both key and value as a string, as you would in a 2d array).

EDIT: This is some json that is in use (Note it’s MUCH longer). This is what is given for “data”

{"feat_3":"4356","feat_4":"45","feat_5":"564","feat_6":"7566"}
  • 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-28T01:21:18+00:00Added an answer on May 28, 2026 at 1:21 am

    Once you’ve deserialized the data (e.g., you have myData, which is an object), you can loop through its keys using for..in, and then build up an array that combines keys and values:

    var myData, dataArray, key;
    myData = $.parse(JSON(data));
    dataArray = [];
    for (key in myData) {
        dataArray.push(key);         // Push the key on the array
        dataArray.push(myData[key]); // Push the key's value on the array
    }
    

    Since myData is the result of deserializing the JSON in data, we know that myData is a generic object (e.g., just a {} as opposed to a new Foo or something like that), so we don’t even need hasOwnProperty. If we didn’t know that, and we only wanted to enumerate myData‘s own keys and values, we would add a hasOwnProperty check:

    var myData, dataArray, key;
    myData = $.parse(JSON(data));
    dataArray = [];
    for (key in myData) {
        if (myData.hasOwnProperty(key)) {
            dataArray.push(key);         // Push the key on the array
            dataArray.push(myData[key]); // Push the key's value on the array
        }
    }
    

    There’s no reason to do that in your case, unless someone has been mucking about with Object.prototype (in which case, take them behind the woodshed, give them a severe hiding, and then have them write “I will not muck about with Object.prototype several hundred times on the chalkboard), but whenever you use for..in, it’s always good to stop and think whether A) The object is guaranteed to be vanilla, and B) If not, do you want only its own properties, or do you also want ones it inherits?

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I am currently running into a problem where an element is coming back from
i got an object with contents of html markup in it, for example: string
I want to construct a data frame in an Rcpp function, but when I
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.