4 Replies Latest reply on Dec 2, 2015 3:40 PM by bsmith RSS
    martingal Explorer

    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.



      • Error trying to convert a JSON into an Infotable
        saeedma Apprentice

         

        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



          • Error trying to convert a JSON into an Infotable
            martingal Explorer

            Hello:

             


            So I'm doing this:



            var json = {'name': 'Bidhan Chatterjee','email': 'bidhan@example.com'},{'name': 'Rameshwar Ghosh','email': 'datasoftonline@example.com'};

            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[i];

                    for(var key in obj){

                        var attrName = key;

                        var attrValue = obj[key];

                   infotabletest.AddRow(yourRowObjectHere);

                 

                      

                    }

                }


            I dunno how to create the yourRowObjectHere.

             



              • Error trying to convert a JSON into an Infotable
                vladimirros Creator

                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[i];
                        var newRow = new Object();
                        newRow.name=obj.name;
                        newRow.email=obj.email;
                        infotabletest.AddRow(newRow);
                    }
                var result=infotabletest;

                 



              • Re: Error trying to convert a JSON into an Infotable
                bsmith Apprentice

                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,