Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
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?
Solved! Go to Solution.
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
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
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
Hi XiaoYing,
It's my pleasure.
Lily