簡體   English   中英

在Java REST中將字符串轉換為JSON

[英]Convert String to JSON in Java REST

我有一個從REST服務生成的JSON對象,看起來像這樣:

  {
    "name": "mark",
    "other_details": "{age:34, gender:male}"
  }

在“ other_details”參數中,必須將值轉換為JSON對象,該對象最終應類似於:

{
    "name": "mark",
    "other_details": "{
                          "age":"34", 
                          "gender":"male"
                      }"
}

我的POJO看起來像:

class Profile{
          String name;
          String other_details;
         //getters and setters
}

我需要一些有關將“ other_details”參數(是字符串)的值轉換為JSON的幫助。 我確實嘗試過使用傑克遜,但沒有用。

任何想法,我應該怎么做!

你pojo應該看起來像

public class Profile{
   String name;
   OtherDetailsClass other_details;
   //getters and setters
}

其他詳細信息類應該看起來像

public class OtherDetailsClass {
    String age;
    String gender;
    //getters and setters
}

嘗試為其他細節添加POJO。

class Profile{
          String name;
          OtherDetails other_details;
         //getters and setters
}

class OtherDetails{
          String name;
          String gender;
         //getters and setters
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM