【发布时间】:2020-05-17 03:27:37
【问题描述】:
下面的响应值中的Hi是字符串,相同的值作为一个对象。如何解析android中这种情况的json
谁能帮我解决一下。
例如,pojo 类中的值 i 被定义为字符串,但在该循环失败后,因为在下一个值中是一个对象。
如何同时运行两个字符串和具有相同键名的对象
回复:
"fields": [
{
"name": "subject",
"value": "Meeting with Lead",
"label": "Subject",
"uitype": "2"
},
{
"name": "reminder_time",
"value": "0",
"label": "Send Reminder",
"uitype": "30"
},
{
"name": "assigned_user_id",
"value": {
"value": "19x1",
"label": "Administrator"
},
"label": "Assigned To",
"uitype": "53",
"type": {
"defaultValue": {
"value": "19x1",
"label": "Administrator"
}
}
},]
循环字段
private void fetchJSON(){
sessionId = getActivity().getIntent().getStringExtra("sessionId");
String operation = "syncModuleRecords";
String module = "Accounts";
String syncToken="";
String mode="public";
final GetNoticeDataService service = RetrofitInstance.getRetrofitInstance().create(GetNoticeDataService.class);
/** Call the method with parameter in the interface to get the notice data*/
Call<SyncModule> call = service.GetSyncModuleList(operation, sessionId, module,syncToken,mode);
/**Log the URL called*/
Log.i("URL Called", call.request().url() + "");
call.enqueue(new Callback<SyncModule>() {
@Override
public void onResponse(Call<SyncModule> call, Response<SyncModule> response) {
Log.e("response", new Gson().toJson(response.body()));
if (response.isSuccessful()) {
Log.e("response", new Gson().toJson(response.body()));
SyncModule syncModule = response.body();
String success = syncModule.getSuccess();
if (success.equals("true")) {
SyncResults results = syncModule.getResult();
Sync sync=results.getSync();
ArrayList<SyncUpdated> syncUpdateds=sync.getUpdated();
for(SyncUpdated syncUpdated:syncUpdateds){
ArrayList<SyncBlocks> syncBlocks=syncUpdated.getBlocks();
for(SyncBlocks syncBlocks1:syncBlocks){
String label=syncBlocks1.getLabel();
ArrayList<SynFields> synFields=syncBlocks1.getFields();
ArrayList<SynFields> jsonArray=syncBlocks1.getFields();
for(SynFields synFields1:synFields){
String name=synFields1.getName();
String value=synFields1.getValue();
String labelfield=synFields1.getLabel();
account_name.add(value);
}
myAdapter = new MyAdapter(getContext(),account_name);
recyclerView.setAdapter(myAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
}
}
Pojo 类:
public class SynFields {
@SerializedName("name")
@Expose
private String name;
@SerializedName("value")
@Expose
private String value;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
@SerializedName("label")
@Expose
private String label;
}
【问题讨论】: