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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Home.json navigation

GianVal
15-Moonstone

Home.json navigation

Hi, I want to use some information within the home.json file which is in the same directory of home.js.

How to load this JSON?

I read this article, https://community.ptc.com/t5/Vuforia-Studio/How-to-include-a-json-file-from-Vuforia-Studio-resources/m-p/729025#M9801

but it uses the /resources/uploaded folder.

Many thanks

ACCEPTED SOLUTION

Accepted Solutions

Hi @GianVal ,

you can use the mentioned technique also to load the Home.json. It is only a different path what could you  check in the project folder - e.g.:

 

 let my_file='Home.json'
  $http.get('app/components/' + my_file).
  success(function(data, status, headers, config) { console.log("-->calling succeeded");
   let myJsonData=data;// in this case is $scope.modelData['model-1']='Info.json';
   
    console.warn(myJsonData); 
  })
  .error(function(data, status, headers, config) {console.log("-->calling  failed");
  });
 

 

This will print the Home.json to the console in preview mode. e.g.:

2022-01-31_19-30-38.jpg

View solution in original post

3 REPLIES 3

Hi @GianVal ,

you can use the mentioned technique also to load the Home.json. It is only a different path what could you  check in the project folder - e.g.:

 

 let my_file='Home.json'
  $http.get('app/components/' + my_file).
  success(function(data, status, headers, config) { console.log("-->calling succeeded");
   let myJsonData=data;// in this case is $scope.modelData['model-1']='Info.json';
   
    console.warn(myJsonData); 
  })
  .error(function(data, status, headers, config) {console.log("-->calling  failed");
  });
 

 

This will print the Home.json to the console in preview mode. e.g.:

2022-01-31_19-30-38.jpg

Hi, I'm using this method to read an external JSON file. How can I use the retrieved file in the whole code as a "global variable"?

e.g. read a json-> get a JSON element to use in another function

Many thanks

without the check more detailed I think the following options could be used

  1. - in case that you will not change the json content you can load this json file each time you go to Stuidio View.
  2. - set the value to applicaiton parameter - so possibly you need to use JSON.stringify() and JSON.parse() when read and save there
  3. - use some of the available in Studio widget as container to save as text ( (e.g. unvisible or use  the text of tmlText widget etc) here is the same - so possibly you need to use JSON.stringify() and JSON.parse() when read and save there
  4. -or create an customized widget which should be container only 
  5. - use some TWX method to save the content to an repository and load later from repository 
Announcements

Top Tags