慕田峪9158850
2022-07-20 16:50:14
我想傳遞來自API 上完成的POST請求的響應(yīng)的 JSON 數(shù)據(jù)。我創(chuàng)建了實現(xiàn) Parcelable 類的共享類。我想利用parcelable類在主要活動中保存少量對象(客戶端信息)JSON響應(yīng)并將它們發(fā)送到第二個活動以僅顯示客戶端信息。這是我各自的代碼,這是api響應(yīng)..{ "success": "true", "message": "Logged in successfuly", "user": { "id": 13, "userNo": "", "name": "Adam", "username": "Adam@gmail.com", "actualPassword": "12345", "email": "apollo@client.com", "secondaryEmail": null, "primaryPhone": 9876544345, "secondaryPhone": null, "clientId": { "clientId": 1, "name": "Charlie", "address": "India", "createdBy": null, "createdAt": "2018-10-25T11:25:19.000Z", "updatedAt": "2019-01-21T10:10:39.000Z", "is_active": 1, "clientCode": "APL", "startTime": "08:00:00.000000", "endTime": "07:59:59.000000", }, "gender": null, "dob": null, "emergencyMobile": null, "officeNo": null, "loggedInStatus": 0, }}
1 回答

慕村225694
TA貢獻1880條經(jīng)驗 獲得超4個贊
由于您的對象實現(xiàn)了 Parcelable,因此只需使用 putExtra() 將它們放入您的 Intent 中:
Intent i = new Intent();
i.putExtra("name_of_extra", myParcelableObject);
然后你可以用getParcelableExtra()把它們拉出來:
Intent i = getIntent();
SharingClass sharingClass = (SharingClass) i.getParcelableExtra("name_of_extra");
如果您必須訪問 POJO 中的數(shù)據(jù),您可以使用 getter 方法獲得,例如在您的情況下。如果您必須訪問 ClientId,那么您可以這樣做。
int clientId = sharingClass.getClientId();
希望這可以幫助。
添加回答
舉報
0/150
提交
取消