如何使用Codable解析后续响应?

时间:2019-10-18 13:07:37

标签: json swift codable

如何使用public class DownloadReceiver extends BroadcastReceiver { private String mDownloadDIR = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString(); private Context mContext = BaseApplication.getAppContext(); @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) { Log.i("DownloadReceiver", "DownloadCompleted!"); File retFile = null; File directory = new File(mDownloadDIR); File[] files = directory.listFiles(); for (File file : files) { Log.i("DownloadReceiver", "Searching file in DOWNLOADS"); if (file.getName().contains(".pdf")) { Log.i("DownloadReceiver", "File found!"); retFile = file; break; } } if (retFile != null) { Log.i("DownloadReceiver", "Go to PDF viewing..."); Intent mGoToPDFView = new Intent(mContext, PDFViewerActivity.class); mGoToPDFView.putExtra("FILE", retFile); mGoToPDFView.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mContext.startActivity(mGoToPDFView); } } } } 解析以下响应

Codable

我想使用{ "Response": { "ResponseStatus": 1,`enter code here` "TraceId": "00125bf6-a416-4095-893c-05e05f8c7202", "Origin": "BOM", "Destination": "PNQ", "Results": [ [ { "IsCouponAppilcable": true, "IsGSTMandatory": false, "AirlineRemark": "AI TEST.", }, { "IsCouponAppilcable": true, "IsGSTMandatory": false, "AirlineRemark": "AI TEST.", } ] ] } } 来解析“结果”

我尝试了此操作,但是卡住了如何解析“结果”

Codable

1 个答案:

答案 0 :(得分:1)

您需要像这样使其响应,因为您在另一个数组中有一个数组。

var Results : [[FlightResult]]?

然后将键/值解析为您的FlightResult结构。