cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Convert Text String to JSON object

Former Member
0 Likes
4,427

Hi,

How can a string be converted to a JSON object in SAPUI5 ?

Example : var mystr = ' [ { name : "Joe", last : "Doe"}, { name : "Jack", last : "Daniel" }]';

How do i convert mystr to a JSON object which can be used in a JSONModel?

$,parseJSON(mystr) or jQuery.parseJSON(myStr) do not seem to exist.

JSONModel.setJSON(mystr) too did not work.

Any pointers ?

regards,

sreeram

View Entire Topic
Former Member
0 Likes

Hi Ben, Chandra, Vladimir,

My mistake. As both Ben and Vladimir have pointed out, the parseJSON expects string with double quotes around the property names.

I came to the wrong conclusion, since the test object could be constructed in Javascript without the quotes. Also, the documentation and editor's choices did not have "parseJSON'.

Now, my code is working.

regards,

sreeram