cancel
Showing results for 
Search instead for 
Did you mean: 

can not read JSON content

janaka1984
Star Contributor
Star Contributor
hi expert,


i used json file like below

hello.json

{"xx":[{

"World":[{


                              "country":[{                                        
                                            "name":"America",
                                            "Area": [
                                                             {
                                                               "areaname":"wosington",
                                                                "target":{}
                                                             },
                                                             {
                                                               "areaname":"florida",
                                                               "target":{}
                                                             }
                                                       ]
                                        }]
       
                }]
        }]

}

——————————————————————————-


To read above json content , i use server side js file. (hello.get.js)



function main() {
  var data = get_config();

  var x = [];

  for(var i = 0; i< data.xx.length; i++){  //loop to get outer
       for(var j = 0; j< data.xx.world.length; j++){  //loop to get advance search
          for(var k = 0; k< data.xx.world[j].country.length; k++){ //loop to get study DB
              for(var t = 0; t< data.xx.world[j].country[j].area[k].areaname.length; t++){//loop to get option
              template_details[t] = data.xx.world[j].country[j].area[k].areaname[t].areaname;
          }
       }
    }
  }

  model.responses = x;

}

function get_config() {
 


  var configfile = companyhome.childByNamePath("/country/hello.json");
  var serverCfg = configfile.content;
 
  return jsonUtils.toString (eval('(' + serverCfg + ')'));
 
 
}

main();

——————————————————————————-



pls correct me or give solution to solve this problem.

hints:  var data = get_config();  (need to check  whether it can assign )



Thanks

hewa

1 REPLY 1

muralidharand
Star Contributor
Star Contributor
Hi,
Please let me know your expected output format for this?

<javascript>

function main() {   
    var data = get_config();  
    model.responses = data;
}

function get_config() {

    var configfile = companyhome.childByNamePath("/country/hello.json");
    var serverCfg = configfile.content;
    return  jsonUtils.toJSONObject(jsonUtils.toObject(serverCfg));
}

main();


</javascript>

Once you got the values on the resposes, you can manipulate it in the output ftl file.