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

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

Translate the entire conversation x

How to read json file inside Vuforia Studio

Aditya1702
16-Pearl

How to read json file inside Vuforia Studio

Hi everyone,

 

I have a json file which has attribute values of a widget in key value pair for eg.

 

"attributes": {
                "twx-widget": "",
                "widget-id": "p2a",
                "widget-name": "p2a",
                "is-widget-container": "true",
                "src": "Uploaded/pin.pvz",
                "scale": "0.5",
                "x": 0.44480000000000003,
                "y": 0.6587000000000001,
                "z": 0.603,
                "rx": "0",
                "ry": "0",
                "rz": "0"
            },
"attributes": {
                "twx-widget": "",
                "widget-id": "p2b",
                "widget-name": "p2b",
                "is-widget-container": "true",
                "src": "Uploaded/pin.pvz",
                "scale": "0.5",
                "x": 0.44480000000000003,
                "y": 0.6587000000000001,
                "z": 0.611,
                "rx": "0",
                "ry": "0",
                "rz": "0"
            }
 
 
How can I assign this value to a widget in Vuforia Studio?
 
Thanks in advance.
 
Regards,
Aditya Gupta
3 REPLIES 3

Similar discussion - "How to include a .json file from Vuforia Studio resources": https://community.ptc.com/t5/Vuforia-Studio/How-to-include-a-json-file-from-Vuforia-Studio-resources/td-p/729025 

Hi @VladimirN ,

 

I tried the link you provided but was not able to read the data from the json file.

 

Can you please explain in more detail about how can I fetch data from json file and change the widget values.

 

Thanks in advance.

 

Regards,

Aditya Gupta

Hi @Aditya1702 ,

I woud think - when the data is assigned to the scope variable myJson

then you can access it 

$scope.myJson= data

e.g. you want to access the x,y and z value

but first to correct that print should be an array so let say the variable name is then $scope.myJsonArray ...

 

$scope.myJsonArray=["attributes": {
                "twx-widget": "",
                "widget-id": "p2a",
                "widget-name": "p2a",
                "is-widget-container": "true",
                "src": "Uploaded/pin.pvz",
                "scale": "0.5",
                "x": 0.44480000000000003,
                "y": 0.6587000000000001,
                "z": 0.603,
                "rx": "0",
                "ry": "0",
                "rz": "0"
            },
"attributes": {
                "twx-widget": "",
                "widget-id": "p2b",
                "widget-name": "p2b",
                "is-widget-container": "true",
                "src": "Uploaded/pin.pvz",
                "scale": "0.5",
                "x": 0.44480000000000003,
                "y": 0.6587000000000001,
                "z": 0.611,
                "rx": "0",
                "ry": "0",
                "rz": "0"
            }]

 

so now when we want to access the x for the first element and set it to value e.g.

 

 

$scope.myJsonArray[0]['attributes'].x=0.46
//or 
$scope.myJsonArray[0].attributes.x=0.46
//or 
$scope.myJsonArray[0]['attributes']['x']=0.46

 

and let say to set Y valuel of the second element it should be  something like that :

 

$scope.myJsonArray[1]['attributes'].y=0.77
//or 
$scope.myJsonArray[1].attributes.y=0.77
//or 
$scope.myJsonArray[1]['attributes']['y']=0.77

 

Announcements
Top Tags