+ Start a Discussion
code developercode developer 

How to get object from JSON parser ?

 

Is there any way to get  object from json response other than deserialize untyped(As it supports only for primitive data types)?

 

 

AmitSahuAmitSahu
JSON will not understand your Objects hence deserializing is the best option..
code developercode developer

 I have a scenario where I get dynamic json response(i.e. json response varies every time).

So, I am  deserialising  using Streaming Json parser,but the json response I get contains nested json objects in that case If I iterate, I may get toomany scripts exception, so is there any other alternative?

 

 

 

AmitSahuAmitSahu
How big can be your response ? To answer the query.. I am not sure of any other method ..
code developercode developer

To parse the dynamic response, I need to consider all the scenarios like :

 

1. nested objects,

2.arrays

3. normal key value pairs.

 


Could you please suggest how to approach this?

AmitSahuAmitSahu
Any sample code that you might have ?
code developercode developer

{
   "response":[
      {
         "field1":"Developer",
         "field2":{
            "type":"Entery Level"
         },
         "field3":{
            "dynamicdata":{
               "Objectfield":{
                  "Objectfield":"abc"
               }
            }
         }
      },
      {
         "field1":"Developer",
         "field2":{
            "certification":"501 certified"
         },
         "field3":{
            "language":"Apex"
         }
      },
      {
         "field1":"Developer",
         "field2":{
            "hasBlog":"true"
         },
         "field3":{
            "Grade":{
               "A":{
                  "marks":10
               }
            }
         }
      },
      {
         "field1":"Developer",
         "field2":{
            "isContributor":"true"
         },
         "field3":{
            "Rank":{
               "A":{
                  "marks":10
               }
            }
         }
      }
   ],
   "response1":{
      "field1":"Developer",
      "field2":{
         "hasBlog":"true"
      },

   }
}

 

 

Could please suggest using the example response above?

field3 highlighted above contains dynamic response.