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

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

Error trying to convert a JSON into an Infotable

martingalaz
1-Newbie

Error trying to convert a JSON into an Infotable

Hello:


I'm using the snippet FROMJson to convert a JSON into an Infotable and I've already created the datashape that actually match the fields on the array of JSON Objects and I still getting this error:

Wrapped org.json.JSONException: JSONObject["dataShape"] not found. Cause: JSONObject["dataShape"] not found.


This is the code behind:


var params = { 

    json: "[{'name': 'Bidhan Chatterjee','email': 'bidhan@example.com'},{'name': 'Rameshwar Ghosh','email': 'datasoftonline@example.com'}]"  /* JSON */

};


// result: INFOTABLE

var result = Resources["InfoTableFunctions"].FromJSON(params);



Thanks.



4 REPLIES 4
smanley
13-Aquamarine
(To:martingalaz)

Hi Martin,


FromJSON is intended to be used for JSON opjects generated by ThingWorx that already include a DataShape object. For externally generated JSON, you'll want to use one of the content loader functions that correspond to one of the RESTful API http methods. Please note that the Content loader functions with a LOAD prefix will be deprecated in future releases of ThingWorx.

Thanks,

Saeed



Hello:


So I'm doing this:



var json = ;

var params = {

infoTableName : "InfoTable",

dataShapeName : "jsontest"

};

// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(jsontest)

var infotabletest = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);


 for(var i=0;i<json.length;i++){

        var obj = json;

        for(var key in obj){

            var attrName = key;

            var attrValue = obj[key];

       infotabletest.AddRow(yourRowObjectHere);

     

          

        }

    }


I dunno how to create the yourRowObjectHere.

 



Hi Martin,

If you just want to add an InfoTable row, the new row object is created like this:
var newEntry = new Object();
newEntry.DataShapeField1 = "value1"; // NUMBER
newEntry.DataShapeField2 = "value2";
 and so on.

I modified the code a bit just for ease of understanding and the following does work:

 for(var i=0;i<json.length;i++){
        var obj = json;
        var newRow = new Object();
        newRow.name=obj.name;
        newRow.email=obj.email;
        infotabletest.AddRow(newRow);
    }
var result=infotabletest;



Can I get a quick clarification please?

Above you mention "Please note that the Content loader functions with a LOAD prefix will be deprecated in future releases of ThingWorx."

If that is the case what is the proper method to load external JSON that will replace the LOAD prefix functions?

Thanks,

Top Tags