Now that getting a handle on the JS/jQuery language, I have these
basic questions

1)  For an JSON object, how do you get the key name?

Example

var json = {field1: "data2", field2: "data2"};

I know how to get the data, but how do you get the field names? IOW, I
want to get the names of the keys.

Is there a method that traverses the JSON and returns key/value?

Do I need regex() or is there a more direct method?

2)  Best way to create a toJSON() string or object.

I didn't see a direct way to do this, if not, is this best way:

   // Create JSON from form input id="wc*" fields

   $jj = $('[EMAIL PROTECTED]').get();
   json = {};
   try {
      for (var j=0; j <$jj.length; j++) {
         json[$jj[j].getAttribute("name")] = $jj[j].value;
      }
   } catch(e) {
     alert("EXCEPTION:\n\n"+e);
     return false;
   }

TIA

--
HLS

Reply via email to