cancel
Showing results for 
Search instead for 
Did you mean: 

How to get single property from JSON model

former_member202516
Participant
0 Kudos

I'm trying to get single porperty value into variable from JSONModel and I just cant get it right.

     var jsonSetTableModel = new sap.ui.model.json.JSONModel();

     jsonSetTableModel.loadData(link);

     console.log(jsonSetTableModel);

I tried like this jsonSetTableModel.getProperty("/d/results/NARTIFACT_ID");

This returns null, what am I doing wrong?

Accepted Solutions (0)

Answers (3)

Answers (3)

batistadavi
Explorer
0 Kudos

Hello! How are you?

In this case I know that zero (0) is the index of the array, but what if I in this case wanted to search inside json when NARTIFACT_ID is equal to "123456789" for example. How do I do that? I want to "do a json search" and return a single record.

Thanks a lot.

former_member182862
Active Contributor
0 Kudos

HI Mijodrag

the path should be /d/results/0/NAME and /d/results/0/NARTIFACT_ID

so it is


jsonSetTableModel.getProperty('/d/results/0/NAME');

jsonSetTableModel.getProperty('/d/results/0/NARTIFACT_ID');

or get the object


jsonSetTableModel.getProperty('/d/results/0');

Thanks

-D

santhu_gowdaz
Active Contributor
0 Kudos

var aData = jsonSetTableModel.getProperty("/d/results");

console.log(aData.NARTIFACT_ID);

former_member202516
Participant
0 Kudos

console.log(aData) returns undefined and console.log(aData.NARTIFACT_ID) no property

Here is the screen shot of JSON also

santhu_gowdaz
Active Contributor
0 Kudos

No way, it should work.

If you are getting the values in    

console.log(jsonSetTableModel);

then,

var aData = jsonSetTableModel.getProperty("/d/results");

console.log(aData.NARTIFACT_ID);

It should come.