Jump to content

Create object problem


lindm

Recommended Posts

Having problems creating the object structure. I want a structure like this:

{
"BFO": {
        		"1": {
            		"text1": "100",
            		"text2": "200",
            		"text3": "300"
        			},
        		"2": {
            		"text1": "400",
            		"text2": "500",
           		 "text3": "600" 
        			} 
    	     }
}

 

I am creating the object with an each iteration in jquery:

function objects() {
	var BFO = new Object();
	BFO["BFO"] = new Object();
	$("tr").each(function(i) {
		BFO["BFO"][i] = new Object();
		BFO["BFO"][i]["text1"]="test";
		BFO["BFO"][i]["text2"]="test";
		BFO["BFO"][i]["text3"]="test";
               	});

 

This generates:

{"BFO":[{"text1":"test","text2":"test","text3":"test"},{"text1":"test","text2":"test","text3":"test"}]}

}

}

 

Almost there but missing the 1, 2 etc and there are [] characters I don't need. Any help to complete appreciated.

 

 

Link to comment
https://forums.phpfreaks.com/topic/233144-create-object-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.