我有不同的fieldNames帶有我感興趣的值的json。他們來自不同的來源。我想把我的興趣領域變成一個普通的名字。例如:Json在java中的預處理
這是原始的JSON:
{"movieName":"A","Leadactor":"","leadActress":"","movieTitle":"","hero":"","heroine":"","source":"IMDB"}
{"movieName":"","Leadactor":"","leadActress":"","movieTitle":"B","hero":"B1","heroine":"B2","source":"Netflix"}
{"movieName":"C","Leadactor":"C1","leadActress":"C2","movieTitle":"","hero":"","heroine":"","source":"IMDB"}
{"movieName":"D","Leadactor":"D1","leadActress":"D2","movieTitle":"","hero":"","heroine":"","source":"IMDB"}
{"movieName":"","Leadactor":"","leadActress":"","movieTitle":"E","hero":"E1","heroine":"E2","source":"Netflix"}
源IMDB我感興趣的領域是從源Netflix的興趣領域不同。我的最終目標是在前臺展示他們。所以試圖讓我感興趣的領域進入共同領域。
我想把它轉換成:
{Name:"A",Actor"A1",Actress"A2","source":"IMDB"}
{Name:"B",Actor"B1",Actress"B2","source":"Netflix"}
{Name:"C",Actor"C1",Actress"C2","source":"IMDB"}
{Name:"D",Actor"D1",Actress"D2","source":"IMDB"}
{Name:"E",Actor"E1",Actress"E2","source":"Netflix"}
我想到的解決辦法是使用正則表達式來刪除所有領域與空值,那麼替換的movieName和movieTitle到名稱。同樣適用於其他領域。
是否有更好的方法來處理這個問題。(JSON的我得到的是非常巨大的,所以尋找超快速的預處理它。)
使用JSON庫而不是正則表達式。 – 2013-03-21 17:16:43
我之前使用過jackson和gson。他們正在創建Java對象,我認爲它是過時的,以在前端顯示它們。我的意思是我必須爲1000個json結果創建10,000個java對象。我正在尋找超快速和高效內存的方式來做到這一點,因爲我得到的json非常龐大。 – javaMan 2013-03-21 17:19:39
您可以使用簡單的[json-simple](http://code.google.com/p/json-simple/),顧名思義。查看解碼示例編號4,您可以將簡單對象解碼爲地圖,修改地圖並從那裏重新編碼。 – 2013-03-21 17:25:39