2015-02-05 58 views
-1

在播放框架中,我找不到任何文檔來定製Java中的JSON結構?所有的文檔都斯卡拉....
定製:在播放框架中爲java語言定製的json格式

Player.java

public class Player { 
    Player (string f, string l, string age) { 
     this.FirstName = f; 
     this.LastName = l; 
     this.Age = age; 
    } 
    public String FirstName ; 
    public String LastName ; 
    public String Age; 
}; 

和運行

list = conn.createQuery(sql);//sql has been created, and list is a list of Player 

現在我有(這種內在張力結構我得到的是從源碼)

Player:[ 
{ 
    FirstName : AAA 
    LastName : BBB 
    Age : 20 
}] 

我想更改爲

Player: [ 
{ 
    Name : { 
     FirstName : AAA 
     LastName :BBB 
    } 
    Age : 20 
}] 

我該如何做到這一點?

+1

什麼是「自定義JSON格式」? JSON是JSON ... – fge 2015-02-05 20:23:54

+0

什麼是_customized JSON格式_? – biesior 2015-02-05 20:25:29

+0

@fge我再次編輯了我的問題 – 2015-02-05 20:31:36

回答

0

非常通用的,你使用Play的toJson(...)方法時:

  • List<Object>將被轉換成JSON數組
  • Map<String, Object>將被轉換成JSON對象
  • 您可以使用它們的任意組合(陣列對象,陣列對象等)

(根據JSON規範:http://json.org/

您只需修復您的Player類以符合這些規則。

+0

嗨@biesior,你能具體怎麼改變球員課程......我仍然有點困惑...... – 2015-02-05 20:52:56