在Java中,我已經通過郵局(例如)通過了這些鍵/值對:從給定的映射到一個JSON字符串(或者的JSONObject)
form_id=undefined
frmb[0][cssClass]=input_text
frmb[0][required]=checked
frmb[0][values]=First Name
frmb[1][cssClass]=input_text
frmb[1][required]=checked
frmb[1][values]=Last Name
frmb[2][cssClass]=textarea
frmb[2][required]=undefined
frmb[2][values]=Bio
frmb[3][cssClass]=checkbox
frmb[3][required]=undefined
frmb[3][title]=What's on your pizza?
frmb[3][values][2][baseline]=undefined
frmb[3][values][2][value]=Extra Cheese
frmb[3][values][3][baselise]=undefined
frmb[3][values][3][value]=Pepperoni
frmb[3][values][4][baseline]=undefined
frmb[3][values][4][value]=Beef
frmb[4][cssClass]=radio
frmb[4][required]=undefined
frmb[4][title]=Do you like pizza?
frmb[4][values][2][baseline]=checked
frmb[4][values][2][value]=Yes
frmb[4][values][3][baseline]=undefined
frmb[4][values][3][value]=No
frmb[5][cssClass]=select
frmb[5][multiple]=checked
frmb[5][required]=checked
frmb[5][title]=Select a pizza type:
frmb[5][values][2][baseline]=checked
frmb[5][values][2][value]=Margherita
frmb[5][values][3][baseline]=undefined
frmb[5][values][3][value]=Napoli
frmb[5][values][4][baseline]=undefined
frmb[5][values][4][value]=Marinara
我已經創建以下JSON:
[{"cssClass":"input_text","required":"checked","values":"First Name"},{"cssClass":"input_text","required":"checked","values":"Last Name"},{"cssClass":"textarea","required":"undefined","values":"Bio"},{"cssClass":"checkbox","required":"undefined","title":"What's on your pizza?","values":{"2":{"value":"Extra Cheese","baseline":"undefined"},"3":{"value":"Pepperoni","baseline":"undefined"},"4":{"value":"Beef","baseline":"undefined"}}},{"cssClass":"radio","required":"undefined","title":"Do you like pizza?","values":{"2":{"value":"Yes","baseline":"checked"},"3":{"value":"No","baseline":"undefined"}}},{"cssClass":"select","required":"checked","multiple":"checked","title":"Select a pizza type:","values":{"2":{"value":"Margherita","baseline":"checked"},"3":{"value":"Napoli","baseline":"undefined"},"4":{"value":"Marinara","baseline":"undefined"}}}]
我該怎麼辦?
我沒有成功在解析鍵,分組做相同的JSONObject的一部分的元素。
很好。它看起來像遞歸的情況。你有什麼嘗試? – 2012-06-09 20:32:25
@pst:其實我想的是遞歸的東西,但我還沒有嘗試過。我想我必須解析鍵,但是我必須創建什麼「結構」來使用org.json來構建json? – Sefran2
只需將其放入相應的「JSONObjects」中即可; org.json版本已經足夠了。它看起來像「是數字鍵」*或*「值」他們創建一個嵌套的JSONObject(遞歸)其他,只是映射到當前級別的屬性。 – 2012-06-09 20:55:35