Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JSON & sub records

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
I've been toying with idea of using JSON for my final working applicatation but am having a little trouble getting my head round it all.

I've been reading this link
I'm a bit confused over this command
Code:
var myObject = JSON.parse(myJSONtext, reviver);

If I had sub set records within the object, how would I know?

I'm assuming from this that after parsing the JSON, myObject would be an array for each master record with the following syntax
Code:
document.write(myObject[0].fldname1);
document.write(myObject[0].fldname2);
document.write(myObject[1].fldname1);
document.write(myObject[1].fldname2);
etc.

But what if fldname3 was a sub record set?

How do I test for existing records or if there are no records, how do you build the JSON data to show it should be a sub set of records but not necessarily containing any sub records.

I'm guessing you could do something like this to access it, but am unsure how I build the data structure to start with.
Code:
if (myObject[RecID].fldname3.length > 0){
   for (i=0; i<myObject[RecID].fldname3.length; i++)
   {
     document.write(myObject[RecID].fldname3[i].fldname1);
     document.write(myObject[RecID].fldname3[i].fldname2);
     document.write(myObject[RecID].fldname3[i].fldname3);
   }
}

Am I on the right track?

Cheers
1DMF

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top