07-20-2023, 12:55 PM
I am reading a set of node in java. each node is of one country. each node has property "country" and for some countries like US has "states" property node too. This "states" is part of a multifield hence each item has one state which is all together in one node something like this:
country = "US"
, states = [{"statename":"District of Columbia"}, {"statename":"Rhode Island"},{"statename":"South Dakota"}]
I want to populate them as a json in the page through a servlet call like this:
{
country: "India"
{
statename:"Delhi",
statename:"Punjab",
statename:"Haryana"
}
}
{
country: "Turkey"
}
following is my code:
while (nodeItr.hasNext()) {
Node cNode = nodeItr.nextNode();
if (cNode.hasProperty("country")) {
JSONObject jsonData = new JSONObject();
jsonData.put("country", childNode.getProperty("countryname").getValue().getString());
jsonArray.put(jsonData);
if (cNode.hasProperty("states")) {
// This should display array of all states as an when it is encountered.
LOG.info(childNode.getProperty("states").getValue().getString());
Following happens:
1. I get all the country list except the first country for which states property is exits.
2. No other country where statelist is there, is displayed.
What am I doing wrong ?
country = "US"
, states = [{"statename":"District of Columbia"}, {"statename":"Rhode Island"},{"statename":"South Dakota"}]
I want to populate them as a json in the page through a servlet call like this:
[To see links please register here]
{
country: "India"
{
statename:"Delhi",
statename:"Punjab",
statename:"Haryana"
}
}
{
country: "Turkey"
}
following is my code:
while (nodeItr.hasNext()) {
Node cNode = nodeItr.nextNode();
if (cNode.hasProperty("country")) {
JSONObject jsonData = new JSONObject();
jsonData.put("country", childNode.getProperty("countryname").getValue().getString());
jsonArray.put(jsonData);
if (cNode.hasProperty("states")) {
// This should display array of all states as an when it is encountered.
LOG.info(childNode.getProperty("states").getValue().getString());
Following happens:
1. I get all the country list except the first country for which states property is exits.
2. No other country where statelist is there, is displayed.
What am I doing wrong ?