Native JS is capable of this sort of thing.

For instance:

var obj = { "p1": "v1", "p2": "v2" };
for (p in obj) {
  document.write( p + " : " + obj[p] + "<br>" );
}

This would output:

p1 : v1
p2 : v2

Using the "for..in" loop structure, you can iterate over each of the properties of a given object. In this case, "p" contains the name of the current property, and by doing "obj[p]", we treat obj as a hash object and get the value of the property in question. The loop then moves on to the next property.

(disclaimer - the document.write() line is for sample purposes only, I'm assuming you'll using something more appropriate....)

This will work with ANY object (assuming my memory isn't tooooo far gone), but will not go into the tree structure. If a propertie is another object, or array, then it's "value" would be displayed as "[object]".

HTH  And I hope this is what you were after.

Shawn

Massimiliano Marini wrote:
Hi Charlie,

I'm not good at explaining the exact terms javascript definitions for
"value and key" but they are javascript identifiers? change it to
what their values are in the array, works great

what I want to do is to print the "name" and the "value" of a json
object without knowing what the object has inside.

The only thing I know is that inside the json object there are only
[{name:value,name:value,name:value}], the object is not fixed lenght
and the name:value are not always the same.

Is it possible?

Reply via email to