Faced the urgent need to write a small JS script (which I never worked on) that would handle JSON. The problem is this. In this JSON there are fields of the form: field_name/_link , field_name/_text . Normal fields are processed normally (without / ), but when you try to query the .field_name/_text , an error is reported that the field is not certain.

Please explain what role does the symbol / in JSON or JS. The main problem is that I do not know where, and what to look for.

  • one
    and did not try? obj ['field_name / _link'] - Jean-Claude
  • @ Jean-Claude Hmm, it's simple. Thank you so much. I tried to get JSON documentation, but it turned out to be much easier. Thank. - Janislav Kornev
  • I'm not special, but it's not exactly JSON, it's more like access to the object's element, but they are a little different. - Jean-Claude
  • @ Jean-Claude This is the problem that I was looking for about JSON, but it turned out that this is purely JS syntax. - Janislav Kornev

1 answer 1

Everything works for me:

 $(function(){ $('#but').on('click', function(){ var obj = jQuery.parseJSON('{"field_name/_link":"someValue"}'); alert("field_name/_link: " + obj['field_name/_link']); }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input id="but" value="alert" type="button">