-2

I have a field sent by SERVICE which is having hypen in it. Eg., first-name (As JSON object)

But when I try to get the value of that field through the jsp. I am getting a script error.

Please let me know how to access the hypen also in this?

var nameList = msg.RESPONSE.DATA.NAME-LIST;

The above way when I try to access it is throwing script error

Venkat
  • 37
  • 6

1 Answers1

1

A variable or property name with an hyphen is indeed wrong in javascript (Jquery).

However, you can access the "problematic" property like this :

var nameList = msg.RESPONSE.DATA["NAME-LIST"];

I would recommend to rename the property(ies) without hyphen if you control the content of this response

Yooz
  • 2,506
  • 21
  • 31