-1

Iam new to java script and JSON, please help me in solving my problem. Below is the structure of my JSON in JavaScript

{
    "name": "sample",
    "def": [
        {
            "setId": 1,
            "setDef": [
                {
                    "name": "ABC",
                    "type": "STRING"
                },
                {
                    "name": "XYZ",
                    "type": "STRING"
                }
            ]
        },
        {
            "setId": 2,
            "setDef": [
                {
                    "name": "abc",
                    "type": "STRING"
                },
                {
                    "name": "xyz",
                    "type": "STRING"
                }
            ]
        }
    ]
}

in the backend, what should be the synatx of java method to receive this data

public void getJsonData(****){

}

How to parse this JSON data in java and what should be the syntax of method parameter ?

update 1: Edited the json format to make it valid

user3131769
  • 365
  • 1
  • 4
  • 9

2 Answers2

0

Your JSON is invalid, but assuming you fix that then you are looking for a library in Java which will serialize an annotated Java class to JSON, or deserialize JSON data to an annotated Java class.

There is a whole list of suitable libraries here:

http://json.org/java/

Tim B
  • 40,716
  • 16
  • 83
  • 128
0

First create a class that will map your json object and give a name something like "DataObject". Then use the gson library and do the following:

String s = "";
DataObject obj = gson.fromJson(s, DataObject.class);
mdagis
  • 116
  • 1
  • 1
  • 6