Skip to content Skip to sidebar Skip to footer

JSON - Access Field Named '*' Asterisk

I am trying to access a JSON field that has the key '*': { 'parse': { 'text': { '*': 'text i want to access' } } } Neither myObject.parse.text.* nor myObject.

Solution 1:

json.parse.text["*"]

Yucky name for an object member.


Asterisks have no special meaning; it's a string like any other.

myObject.parse.text.* doesn't work because * isn't a legal JS identifier. Dot notation requires legal identifiers for each segment.

myObject.parse.text[0] doesn't work because [n] accesses the element keyed by n or an array element at index n. There is no array in the JSON, and there is nothing with a 0 key.

There is an element at the key '*', so json.parse.text['*'] works.


Solution 2:

Try use the index operator on parse.text:

var value = object.parse.text["*"];

Solution 3:

try to use

var text = myObject.parse.text['*']

Solution 4:

You could do:

var json = {"parse":
 {"text":
  {"*":"text i want to access"}
 }
}

alert(json.parse.text['*']);

Post a Comment for "JSON - Access Field Named '*' Asterisk"