Skip to Content
-1

How to extract data from a JSONModel object in SAP UI5

var oUserModel = new sap.ui.model.json.JSONModel("/services/userapi/currentUser");

//By this i am getting the data of the current user.

console.log(oUserModel)


//when i print it in console I get the currentUser data in the oData Section of the object.Can I know how to extract the data.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Posted on Nov 04, 2019 at 09:31 AM

    Hi Amit,

    ok sorry, I thought the service work.

    For information about user I'm using this :

    sap.ushell.Container.getUser()
    


    without json model.

    Sebastiano

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 05, 2019 at 07:36 AM

    Amit,

    If you want to view data before databinding.

    You should loaddata into json using

    var oUserModel =new sap.ui.model.json.JSONModel();
    oUserModel.loadData("/services/userapi/currentUser");
    //now check data 
    console.log(oUserModel.getData()); 

    Hope helps.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 05, 2019 at 09:21 AM

    Hi Amit,

    You can get JSON data by this way.

    var oUserModel = new sap.ui.model.json.JSONModel("/services/userapi/currentUser"); 
    var data = JSON.parse(oUserModel.getJSON());

    Regards,

    Manjunatha Devadiga

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.