有問題,我得到了一個JSON響應來自一個請求,我將其轉換爲字符串可以說:替換字符串...什麼,我想
String response = client.execute(get, handler);
響應看起來像:
"geometry":{"rings":[[[29470.26099999994,40220.076999999583],[29551.560999999754,40324.093000000343],[29597.470999999903,40391.253000000492],[29619.849999999627,40434.842000000179],[29641.708999999799,40471.713999999687],[29701.501000000164,40574.616000000387],[29722.775999999605,40611.230000000447],[29723.673000000417,40613.234999999404]]]}
但我想有它看起來像下列操作之一:
"Coordinates":"29470.26099999994|40220.076999999583,29551.560999999754|40324.093000000343,29597.470999999903|40391.253000000492,45360.235000003|41478.4790000003,45360.2369999997|41478.4729999993,45353.8320000004|41470.7339999992,45372.21|41468.057,45371.8090000004|41467.1390000004"
總之我想改變逗號betwe在[]集中的兩個座標用管道隔開「|」逗號,而不是和分離一組與兩個座標,而不是「],[」
我的嘗試:
response = response.replace("],[","\,");
response = response.replace("[[[","\"");
response = response.replace("]]]","\"");
但是它並沒有給我什麼,我想...... becuz我有沒有想法實現管道的替換...使用正則表達式但不知道如何。有人可以幫我請
寫抄錄該問題的簡單主要功能。 – ceving
替換不使用正則表達式... – assylias
也許有點偏離主題,但它似乎你試圖解析JSON字符串。爲什麼不使用JSON解析器獲取Java對象,然後實現toString方法? – Thomas