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

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

About Convert JSON file to Infotable

xcheung
1-Newbie

About Convert JSON file to Infotable

I follow the document: https://support.ptc.com/appserver/cs/view/solution.jsp?n=CS179012 to convert JSON file to Infotable, so I:

1. Create the Datashape based on the JSON key and value.

2. Create the service to getJSON file, and the code is:

var params = {

proxyScheme: undefined /* STRING */,

headers: undefined /* JSON */,

ignoreSSLErrors: true /* BOOLEAN */,

useNTLM: undefined /* BOOLEAN */,

workstation: undefined /* STRING */,

useProxy: undefined /* BOOLEAN */,

withCookies: undefined /* BOOLEAN */,

proxyHost: undefined /* STRING */,

url:"http://servername/rest/sql/list/site/",

timeout: undefined /* NUMBER */,

proxyPort: undefined /* INTEGER */,

password: undefined /* STRING */,

domain: undefined /* STRING */,

username: undefined /* STRING */

};

// result: JSON

var data = Resources["ContentLoaderFunctions"].GetJSON(params);

var params = {

infoTableName: undefined /* STRING */,

dataShapeName: "TestJSON" /* DATASHAPENAME */

};

// result: INFOTABLE

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

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

{

    jsonTable.AddRow({id:data.array.id, area:data.array.area, group:data.array.group, WS_name:data.array.WS_name, state:data.array.state, child:data.array.child});

}

//}

result = jsonTable;

3. After save and test, the result is an empty infotable.

Can anyone help?

1 ACCEPTED SOLUTION

Accepted Solutions
liliu
8-Gravel
(To:xcheung)

Hi Mr. Cheung,

Please provide the structure of your JSON file? Do you have a arrays?

Usually, JSON content rows and use below code to convert to infotable

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

{

    jsonTable.AddRow({id:data.rows.id, area:data.rows.area, group:data.rows.group, WS_name:data.rows.WS_name, state:data.rows.state, child:data.rows.child});

}

If still not works, please let me know.

BR,

Lily

View solution in original post

3 REPLIES 3
liliu
8-Gravel
(To:xcheung)

Hi Mr. Cheung,

Please provide the structure of your JSON file? Do you have a arrays?

Usually, JSON content rows and use below code to convert to infotable

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

{

    jsonTable.AddRow({id:data.rows.id, area:data.rows.area, group:data.rows.group, WS_name:data.rows.WS_name, state:data.rows.state, child:data.rows.child});

}

If still not works, please let me know.

BR,

Lily

xcheung
1-Newbie
(To:liliu)

Hi Lily,

Thank you for your kind reply.

Content of my JSON file is a bit different when using the GetJSON function. So I changed the AddRow function from ({Name:json.name })to ({Name:data.rows.name}, and then got the correct Infotable, thanks again.

XiaoYing

liliu
8-Gravel
(To:xcheung)

Hi XiaoYing,

It's my pleasure.

Lily

Top Tags