2016-11-16 77 views
0

我在用這樣的方法簽名Groovy類休息端點....轉換java.io.BufferedReader中,以JSON對象

public PostMyResponse postMyRequest(Reader arg0) throws Exception { 

Reader是一個java.io.BufferedReader中。在我的帖子請求我傳入json。

如果我做這樣的事情,我可以看到的參數(注:我知道,這是打印出來的Java的方式循環字符串這不是我所追求的)....

 int value=0; 

     // reads to the end of the stream 
     while((value = arg0.read()) != -1) 
     { 
      // converts int to character 
      char c = (char)value; 

      // prints character 
      System.out.println(c); 

我所追求的是一種將java.io.BufferedReader轉換爲使用groovy的Json對象然後從json對象讀取屬性的方法?

感謝

+0

[序號化和反序列化bean的可能的複製到json與Groovy](http://stackoverflow.com/questions/27250386/serialize-deserialize-bean-to-json-with-groovy) – AxelH

回答

1

爲什麼不只是做:

def result = new JsonSlurper().parse(reader) 

然後result將是一個表示(地圖和列表)任何的JSON是你的讀者

+0

這是迄今爲止最好的解決方案。謝謝 – Richie