第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將 JSON 對象從 JsonSlurper 轉換回附加的 JSONArray - Groovy

將 JSON 對象從 JsonSlurper 轉換回附加的 JSONArray - Groovy

紅糖糍粑 2021-10-28 17:10:14
我有一個包含許多 json 消息的 json 數組。然后我解析 json 消息以處理每個 json 對象。我需要弄清楚如何獲取一個失敗的 json 對象并將所有失敗的 json 對象附加回另一個 json 數組以創(chuàng)建一個新文件。我不確定如何將 json 對象從 parseText() 方法轉換回普通的 json 消息,或者如何將對象附加回 json 數組以創(chuàng)建文件。有人可以幫我弄這個嗎?    Main json file array    [      {        "Account": "1",        "Name":    "Test1"      },      {        "Account": "2",        "Name":    "Test2"      },      {        "Account": "3",        "Name":    "Test3"      },      {        "Account": "4",        "Name":    "Test4"      }    ]      String sJson = groovy.json.StringEscapeUtils.unescapeJava(jsonFile.toString());    jsonResp = new groovy.json.JsonSlurper().parseText(sJson));    for( int x=0; x < jsonResp?.size(); x++ ) {        processJson( jsonResp[x] )    }    void processJson( Object jsonResp ) {       If object message fails in this function, need to convert the json object back into a json message       and append it to a jsonArray to create a new json file.    }    This is what the new json file would like if test samples 2 & 4 failed    [      {        "Account": "2",        "Name":    "Test2"      },      {        "Account": "4",        "Name":    "Test4"      }    ]  
查看完整描述

1 回答

?
瀟湘沐

TA貢獻1816條經驗 獲得超6個贊

我找到了我的問題的答案。


JSONArray jsonArray = new JSONArray();

jsonArray.add(jsonResp);

println jsonArray.toString()


查看完整回答
反對 回復 2021-10-28
  • 1 回答
  • 0 關注
  • 222 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號