0

I am writing a program to fetch data from a server by sending a request. The all values are in JSON format.

I am not able to understand whether JSONobject is containing JSONArray or JSONArray is containing object.

My data is in the following format :

{
    "items": [
        {
            "name": "accounts",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/accounts"
                }
            ]
        },
        {
            "name": "analyticsReports",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/analyticsReports"
                }
            ]
        },
        {
            "name": "answers",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/answers"
                }
            ]
        },
        {
            "name": "assets",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/assets"
                }
            ]
        },
        {
            "name": "assetStatuses",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/assetStatuses"
                }
            ]
        },
        {
            "name": "channelTypes",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/channelTypes"
                }
            ]
        },
        {
            "name": "configurations",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/configurations"
                }
            ]
        },
        {
            "name": "contacts",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/contacts"
                }
            ]
        },
        {
            "name": "countries",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/countries"
                }
            ]
        },
        {
            "name": "eventSubscriptions",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/eventSubscriptions"
                }
            ]
        },
        {
            "name": "holidays",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/holidays"
                }
            ]
        },
        {
            "name": "incidents",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/incidents"
                }
            ]
        },
        {
            "name": "mailboxes",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/mailboxes"
                }
            ]
        },
        {
            "name": "marketingMailboxes",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/marketingMailboxes"
                }
            ]
        },
        {
            "name": "messageBases",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/messageBases"
                }
            ]
        },
        {
            "name": "opportunities",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/opportunities"
                }
            ]
        },
        {
            "name": "organizations",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/organizations"
                }
            ]
        },
        {
            "name": "purchasedProducts",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/purchasedProducts"
                }
            ]
        },
        {
            "name": "salesProducts",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/salesProducts"
                }
            ]
        },
        {
            "name": "salesTerritories",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/salesTerritories"
                }
            ]
        },
        {
            "name": "serviceCategories",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/serviceCategories"
                }
            ]
        },
        {
            "name": "serviceDispositions",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/serviceDispositions"
                }
            ]
        },
        {
            "name": "serviceMailboxes",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/serviceMailboxes"
                }
            ]
        },
        {
            "name": "serviceProducts",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/serviceProducts"
                }
            ]
        },
        {
            "name": "siteInterfaces",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/siteInterfaces"
                }
            ]
        },
        {
            "name": "sSOTokenReferences",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/sSOTokenReferences"
                }
            ]
        },
        {
            "name": "standardContents",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/standardContents"
                }
            ]
        },
        {
            "name": "tasks",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/tasks"
                }
            ]
        },
        {
            "name": "variables",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/variables"
                }
            ]
        },
        {
            "name": "Asset.TypeOfInstallation",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/Asset.TypeOfInstallation"
                }
            ]
        },
        {
            "name": "Asset.AssetType",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/Asset.AssetType"
                }
            ]
        },
        {
            "name": "Asset.AMC_Warranty",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/Asset.AMC_Warranty"
                }
            ]
        },
        {
            "name": "Asset.Vendor",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/Asset.Vendor"
                }
            ]
        },
        {
            "name": "BOB.BOB",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/BOB.BOB"
                }
            ]
        },
        {
            "name": "BOB.Beverages_Name",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/BOB.Beverages_Name"
                }
            ]
        },
        {
            "name": "BOB.Supply_Name",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/BOB.Supply_Name"
                }
            ]
        },
        {
            "name": "BOB.Recipes",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/BOB.Recipes"
                }
            ]
        },
        {
            "name": "BOB.UOM",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/BOB.UOM"
                }
            ]
        },
        {
            "name": "BOM.Bill_On_Material",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/BOM.Bill_On_Material"
                }
            ]
        },
        {
            "name": "BOS.Bill_On_Supply",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/BOS.Bill_On_Supply"
                }
            ]
        },
        {
            "name": "Depreciate.Depreciation",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/Depreciate.Depreciation"
                }
            ]
        },
        {
            "name": "Depreciate.Operator_Cost",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/Depreciate.Operator_Cost"
                }
            ]
        },
        {
            "name": "Site_Inspec.Site_Status_Install",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/Site_Inspec.Site_Status_Install"
                }
            ]
        },
        {
            "name": "Spares.Spares",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/Spares.Spares"
                }
            ]
        },
        {
            "name": "Spares.Spares_Consumption",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/Spares.Spares_Consumption"
                }
            ]
        },
        {
            "name": "Spares.Item_Category",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/Spares.Item_Category"
                }
            ]
        },
        {
            "name": "Spares.Item_Request",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/Spares.Item_Request"
                }
            ]
        },
        {
            "name": "Spares.Spares_Request",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/Spares.Spares_Request"
                }
            ]
        },
        {
            "name": "queryResults",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest/queryResults"
                }
            ]
        }
    ],
    "links": [
        {
            "rel": "self",
            "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest"
        },
        {
            "rel": "canonical",
            "href": "https://lavazzaindia--tst1.custhelp.com/services/rest/connect/latest"
        }
    ]
}

I have understood this data by using a JSONEditor that here are 2 JSON Objects named items and links.

And these two objects contains JSONArray.

I am getting all values in java program using following loop:

         String output;
            System.out.println("Output from Server .... \n");
            while ((output = br.readLine()) != null) {
                System.out.println(output);
            }

Here I am getting the output as data is shown but I need output in JSON object.

What should I do in while loop so that I can get JSONObject as my object.

Please somebody help me out, that how can I parse these JSON data into seperate objects. I am totally confused here.

Where and how I've to convert from JSONArray, JSONObject or String?

Shambhu
  • 121
  • 3
  • 11
  • 2
    An object starts with `{`. An array starts with `[`. What do you conclude? – JB Nizet Jun 27 '17 at 11:21
  • Yeah, but I need objects in java program, then what method I've to use inside loop? And that too I am getting output as `BufferedReader` value. – Shambhu Jun 27 '17 at 11:44
  • Json is not parsed line by line. It is not a line-based format. Read the duplicate. – JB Nizet Jun 27 '17 at 11:49

0 Answers0