2016-06-28 69 views
0

DealItemCaption介紹對象到使用Groovy

BigDealTicket

因爲我是一個有點新的Groovy中,我想請教您有關與使用Groovy JSON串聯以下問題的另一個JSON (請參閱附件中關於問題的圖片)。 我這裏有這裏JSON輸入,我想使用再現的Groovy:

{"isFinancial":false, 
"isPortfolioTransfer":false, 
"type":"ESS", 
"commodity":"Electricity", 
"timezone":"CET", 
"dealDateTime":1466671066373, 
"dealItems":[{"type":"Energy.StandardShape.FixedPrice", 
       "locationType":"grid", 
       "dealItemUDFs":[], 
       "priceType":"fixed", 
       "holidayCalendarId":10001, 
       "quantityUnitId":26, 
       "priceUnitId":12, 
       "dealStart":1483267154000, 
       "dealEnd":1514716754000, 
       "shapeId":2, 
       "balancingGroupId":2, 
       "locationId":41, 
       "quantity":15000, 
       "price":30}], 
"brokerFeeCurrencyId":1, 
"dealTypeId":2, 
"internalEntityId":1399, 
"internalTraderId":305, 
"internalPortfolioId":1, 
"buySell":"-1", 
"externalEntityId":1443, 
"priceRegionId":37, 
"label":"Third Deal Ticket as JIRA Test Candidate", 
"comments":"Third Deal Ticket as JIRA Test Candidate"} 

我有內部JSON(由[]括號中限定的陣列內使用的一個)中產生用JSONBuilder並且還沒有通過JSONBuilder問題產生外JSON,然而,似乎是對於給定輸出的allignment化妝品的問題如下:

{"isFinancial":false, 
"isPortfolioTransfer":false, 
"type":"ESS", 
"commodity":"Electricity", 
"timezone":"CET", 
"dealItems":[{"value":"Energy.StandardShape.FixedPrice","key":"type"}, 
       {"value":"grid","key":"locationType"}, 
       {"value":[],"key":"dealItemUDFs"}, 
       {"value":"fixed","key":"priceType"}, 
       {"value":10001,"key":"holidayCalendarId"}, 
       {"value":26,"key":"quantityUnitId"}, 
       {"value":12,"key":"priceUnitId"}, 
       {"value":1483225200000,"key":"dealStart"}, 
       {"value":1514674800000,"key":"dealEnd"}, 
       {"value":2,"key":"shapeId"}, 
       {"value":1,"key":"balancingGroupId"}, 
       {"value":42,"key":"locationId"}, 
       {"value":15000,"key":"quantity"}, 
       {"value":30,"key":"price"}], 
"dealDateTime":1467116296197, 
"brokerFeeCurrencyId":6, 
"dealTypeId":2, 
"internalEntityId":1399, 
"internalTraderId":306, 
"internalPortfolioId":1, 
"buySellId":"-1", 
"externalEntityId":1443, 
"priceRegionId":37, 
"label":"Latest JIRA Test Case Candidate", 
"comments":"Latest JIRA Test Case Candidate"} 

取而代之的是價值的密鑰對的dealItems應該有以下 JSON

[{"type":"Energy.StandardShape.FixedPrice", 
"locationType":"grid", 
"dealItemUDFs":\[\], 
"priceType":"fixed", 
"holidayCalendarId":10001, 
"quantityUnitId":26, 
"priceUnitId":12, 
"dealStart":1483225200000, 
"dealEnd":1514674800000, 
"shapeId":2, 
"balancingGroupId":1, 
"locationId":42, 
"quantity":15000, 
"price":30}][1] 

回答

0

您是否嘗試過使用grails.converters.JSON

下應該做的正是你想要的:

grails.converters.JSON.parse(""" 
    {"isFinancial":false, 
    "isPortfolioTransfer":false, 
    "type":"ESS", 
    "commodity":"Electricity", 
    "timezone":"CET", 
    "dealDateTime":1466671066373, 
    "dealItems":[{"type":"Energy.StandardShape.FixedPrice", 
       "locationType":"grid", 
       "dealItemUDFs":[], 
       "priceType":"fixed", 
       "holidayCalendarId":10001, 
       "quantityUnitId":26, 
       "priceUnitId":12, 
       "dealStart":1483267154000, 
       "dealEnd":1514716754000, 
       "shapeId":2, 
       "balancingGroupId":2, 
       "locationId":41, 
       "quantity":15000, 
       "price":30}], 
    "brokerFeeCurrencyId":1, 
    "dealTypeId":2, 
    "internalEntityId":1399, 
    "internalTraderId":305, 
    "internalPortfolioId":1, 
    "buySell":"-1", 
    "externalEntityId":1443, 
    "priceRegionId":37, 
    "label":"Third Deal Ticket as JIRA Test Candidate", 
    "comments":"Third Deal Ticket as JIRA Test Candidate"} 
""") 

希望幫助!

+0

非常感謝你吉姆 - 我會嘗試這個解決方案。順便再提一個問題:這個圖書館在哪裏?我在這裏指的是將其導入到SOAP UI的可能性,當然 –

+0

所以你的意思是說,基本上如果我想我的大JSON中的DealItems鍵下的值具有相同的結果,如第二個摘錄中所發佈的,我只需要使用這個庫? (對不起,如果我不清楚上一個問題,我的意思是把第二部分的JSON作爲一個數組元素,而不是顯示鍵值對的JSON - 兩個JSON在單獨使用時都能正確生成,問題與他們的加入)。感謝您的理解 –

+0

道歉,我提到的插件是一個grails插件,可在此處找到:https://grails.org/wiki/Converters%20Plugin。 –