Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am currently building a web project using underscore.js. Currently I am facing the problem that api sends a JSON result (with Many root element) which doesn't get understood by underscore.js because it has many root element. that's why underscore.js reads all data of only first root element...(not all data)


json combine response
C#
{
"API_Reply" : {
       "Product" : [{
             "child" : "NN3", 
              "type" : 3,
              "name" : "No. 1 lounge - Terminal 3",

                       }
                    ],
"API_Header" : {
     "Request" : {
           "token" : 514099508,
           "key" : "abc",
            "v" : 1,
            "format" : "js",
            "version" : "lite"
              }
        }
}
} {  

   "API_Reply" : {
       "Product" : [{
             "child" : "NN2", 
              "type" : 3,
              "name" : "No. 1 lounge - Terminal 2",

                       }
                    ],
"API_Header" : {
     "Request" : {
           "token" : 514099508,
           "key" : "abc",
            "v" : 1,
            "format" : "js",
            "version" : "lite"
              }
        }
}

} {  

   "API_Reply" : {
       "Product" : [{
             "child" : "NN2", 
              "type" : 3,
              "name" : "No. 1 lounge - Terminal 2",

                       }
                    ],
"API_Header" : {
     "Request" : {
           "token" : 514099508,
           "key" : "abc",
            "v" : 1,
            "format" : "js",
            "version" : "lite"
              }
        }
}


there are many root element(Api_Reply) and many tag(Product) ,i want to merge them into one...and Api_header section as it is same and repeating every time.
like below (one root element "Api_Reply" and all product details in one category "Product")

Required Json format
C#
{
"API_Reply" : {
     "Product" : [{
             "child" : "NN3", 
              "type" : 3,
              "name" : "No. 1 lounge - Terminal 3",

                       },{

             "child" : "NN2", 
              "type" : 3,
              "name" : "No. 1 lounge - Terminal 2",

                       }

                 },{

            "child" : "NN2",

             "type" : 3,

           "name" : "No. 1 lounge - Terminal 2",

                       }

             }],
"API_Header" : {
     "Request" : {
           "token" : 514099508,
           "key" : "abc",
            "v" : 1,
            "format" : "js",
            "version" : "lite"
              }
        }
}


Has someone a simple and understandable solution?
Posted
Updated 19-Aug-14 22:40pm
v2
Comments
_debasis 20-Aug-14 9:26am    
Hi Umesh,
Are you getting the whole json at a single API call?
Umesh Parshad 7-Nov-14 7:03am    
no actually i am getting a piece of json code on one call

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900