我是android初学者可以任何人告诉我如何解析一个修复数组下的所有Json数组我要解析父类中的所有数组名称
以下是Json示例:
{
"err-code": 0,
"worksheet": [
{
"2016-08-19": [
{
"worksheet_id": 130,
"job_no": "ES100353-AF",
"message": "Matthew Smith has submitted Worksheet for Approval",
"added_date": "19 Aug 2016",
"added_time": "06:31 AM",
"status": "Pending"
}
],
"2016-08-18": [
{
"worksheet_id": 107,
"job_no": "ES100353-AF",
"message": "Matthew Smith has submitted Worksheet for Approval",
"added_date": "18 Aug 2016",
"added_time": "05:31 AM",
"status": "Pending"
}
]
}
]
}
答案 0 :(得分:1)
您可以使用Android的本机JSON解析器解析JSON,如下所示:
public ParsedData parseWorksheet(String in) throws JSONException {
JSONObject reader = new JSONObject(in);
String errCode = reader.getString("err-code");
JSONArray jsonArrayOuter = reader.optJSONArray("worksheet");
ParsedData parsedData = new ParsedData();
parsedData.errCode = errCode;
for(int i=0; i < jsonArrayOuter.length(); i++){
JSONObject jsonObject = jsonArrayOuter.getJSONObject(i);
Iterator<String> iterator = jsonObject.keys();
ArrayList<Worksheet> worksheetArrayList = new ArrayList<Worksheet>();
while(iterator.hasNext()){
Worksheet worksheet= new Worksheet();
String key = (String)iterator.next();
worksheet.worksheetDataKey = key;
JSONArray jsonArrayW = jsonObject.optJSONArray(key);
WorksheetInnerData[] WorksheetDataArray = new WorksheetInnerData[jsonArrayW.length()];
for(int j=0; j < jsonArrayW.length(); j++){
JSONObject jsonObjectWorksheetData = jsonArrayW.getJSONObject(j);
WorksheetInnerData worksheetData= new WorksheetInnerData();
String worksheet_id = jsonObjectWorksheetData.getString("worksheet_id");
worksheetData.worksheet_id = worksheet_id;
String job_no = jsonObjectWorksheetData.getString("job_no");
worksheetData.job_no = job_no;
String message = jsonObjectWorksheetData.getString("message");
worksheetData.message = message;
String added_date = jsonObjectWorksheetData.getString("added_date");
worksheetData.added_date = added_date;
String status = jsonObjectWorksheetData.getString("status");
worksheetData.status = status;
WorksheetDataArray[j] = worksheetData;
}
worksheet.WorksheetInnerDataArray = WorksheetDataArray;
worksheetArrayList.add(worksheet);
}
parsedData.worksheetArray = worksheetArrayList;
}
return parsedData ;
}
以下应该是您的数据模型:
private static class ParsedData {
public String errCode;
public ArrayList<Worksheet> worksheetArray;
}
private static class Worksheet {
public String worksheetDataKey;
public WorksheetInnerData WorksheetInnerDataArray [];
}
private static class WorksheetInnerData {
public String worksheet_id;
public String job_no;
public String message;
public String added_date;
public String status;
}
希望它有所帮助!!!
答案 1 :(得分:1)
将json数据解析为文件非常简单, 1)。如果是真的,你需要第一个String对象
2)然后将JsonArray与其对象一起获取“工作表”数组 该 3)。现在你的问题是:你有大量的json数组 然后a)。使用Iterator通过Iterator获取所有数组键 并将其保存到arraylist。 b)。和string对象将它传递给JSONArray(Stringkey); c)现在使用循环获取json数组中的所有字符串 d)并将所有内容保存到您要保存的位置 完成..
这是你可以解析的方式
答案 2 :(得分:0)
INSERT INTO (
SELECT `table_name`
FROM `tables`
WHERE `id`=1)(`data_column_name`)
VALUES ('some data')
答案 3 :(得分:0)