简体   繁体   中英

How to store JSON Array inside List in java?

I'm passing json array from angularjs, and it's comes on Spring Controller, I catch it there at @RequestBody String data

I want to store those data inside List,

I tried this,

List<RegisterDTO> stdList = JsonConvert.DeserializeObject<RegisterDTO>(data);

But I don't know JsonConvert from where it's coming? I'm getting an error there(cannot to be resolved).

RegisterController.java

@ResponseBody
@RequestMapping(value = "/registerStudent.do", method = RequestMethod.POST)
public boolean registerStudent(@RequestBody String data) {
    System.out.println(data);
    if (stdList != null) {
        // store stdList
    }
    return registerService.isStudentExist(stdList);

}

So What you have provided is example of Newtonsoft JSON.net used for c#

For Java you have to use different libraries.

Like GSON

Here is an example on How to deserialize json string into object in JAVA

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM