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 7630533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:07:46+00:00 2026-05-31T06:07:46+00:00

So I’m having some issus with JSON. setupdata({NON-RELIGOUS ORGANIZATIONS:{23:[NON-RELIGOUS ORGANIZATIONS,Does this Loce test 2,,null]},YARD

  • 0

So I’m having some issus with JSON.

setupdata({"NON-RELIGOUS ORGANIZATIONS":{"23":["NON-RELIGOUS ORGANIZATIONS","Does this Loce test 2","",null]},"YARD SALES":{"1":["YARD SALES","yard sale","1332599400",null],"22":["YARD SALES","LOCKING TEST YARD SALE a change and more","1331814600",null],"21":["YARD SALES","Generic Yard Sale Title","",null]}})

And I’m processing it with….

function setupdata(data){

   alert(data.length);
   for(i=0; i<data.length; i++) {
   newdiv = document.createElement("DIV");
   newdiv.setAttribute("id","cat"+i);
   newdiv.innerHTML(\'test\');
   document.getElementById(\'divmiddle\').appendChild(newdiv);
   }
 }

I’m getting UNDEFINED for the data.length and also the i loop is not running because it is undefined. I guess I’m just a bit confused about how to parse through the data I return from the JSON call. Any help apppreciated.

AND THE WINNING ANSWER IS

Creating the Arrays in PHP:

while($getcats = mysqli_fetch_array($query)){
$layout[$getcats[news_cat_name]];
if(!$getstories = mysqli_query($connection,"SELECT news_id,news_title,news_organization,news_expiration from news_items where news_category='$getcats[news_cat_id]'")){ echo mysqli_error($connection);}
while($looptitles=mysqli_fetch_array($getstories)){

$layout[$getcats[news_cat_name]][$looptitles[news_id]][]=date("m/d/y G:i a",$looptitles[news_expiration]);

 $layout[$getcats[news_cat_name]][$looptitles[news_id]][]=$looptitles[news_title];

$layout[$getcats[news_cat_name]][$looptitles[news_id]][]=$looptitles[news_organization];

}
}

AND THE RESULTANT JSON

setupdata({"NON-RELIGOUS ORGANIZATIONS":{"23":[false,"Does this Loce test 2","2"]},
"YARD SALES":{
     "1":["03\/24\/12 10:30 am","yard sale","0"]
     ,"22":["03\/15\/12 8:30 am","LOCKING TEST YARD SALE a change and more","0"],
     "21":[false,"Generic Yard Sale Title","0"]}})

AND THE JS to PARSE THE JSON

for(var key in data){//OUTER LOOP FOR THE MAIN OBJECTS
  divkey = document.createElement("DIV");
  divkey.setAttribute("id",key);
  divkey.style.fontSize = \'13px\';

  divkey.style.textDecoration = \'underline\';
  divkey.style.paddingTop = \'3px\';
  divkey.style.paddingBottom = \'5px\';
  divkey.style.position = \'relative\';
  divkey.innerHTML = key;
      document.getElementById(\'divmiddle\').appendChild(divkey);

  for(var mykey in data[key]){//INNER LOOP FOR THE INNER OBJECTS
         divkey = document.createElement("DIV");
     divkey.setAttribute("id",mykey);
         divkey.style.fontFamily = \'Verdana\';
         divkey.style.fontSize = \'11px\';
     divkey.style.paddingBottom = \'5px\';

     divkey.style.position = \'relative\';
     divkey.innerHTML = +data[key][mykey][1]+\' -- \' + data[key][mykey][0];
         document.getElementById(\'divmiddle\').appendChild(divkey);
   }
  }
 }

** I hope this helps someone with a complete solution since there are partial postings all over the place.**

  • 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-31T06:07:47+00:00Added an answer on May 31, 2026 at 6:07 am
    setupdata({ "NON-RELIGOUS ORGANIZATIONS": { "23": ["NON-RELIGOUS ORGANIZATIONS", "Does this Loce test 2", "", null] }, "YARD SALES": { "1": ["YARD SALES", "yard sale", "1332599400", null], "22": ["YARD SALES", "LOCKING TEST YARD SALE a change and more", "1331814600", null], "21": ["YARD SALES", "Generic Yard Sale Title", "", null]} });
       function setupdata(data) {
           alert(JSON.stringify(data));
           alert(data.length);
           for (var key in data) {
               alert(JSON.stringify(data[key]['23']));
               newdiv = document.createElement("DIV");
               newdiv.setAttribute("id", "cat" + data[key]['23']);
               newdiv.innerHTML = 'test';
               document.getElementById('divmiddle').appendChild(newdiv);
           }
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
We're building an app, our first using Rails 3, and we're having to build

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.