I received data from api hit that is base64 encoded. So i converted it into string and decoded it using extension method. After this again converted into data using utf8.
do{
let jsonResult = String(data: data, encoding: .utf8)
let jsonDecryptedString = jsonResult?.fromBase64()
let jsonData = jsonDecryptedString?.data(using: .utf8)
}catch let err{
print(err)
}
This is my Json String (jsonDecryptedString)
{
'error_Code': '0',
'error_msg' : 'Valid Request',
'Report_list' :
[
{
“ReportID" : "LEGAL-01","ReportRdlName" : "Statement of Suit filed Accounts(Pending for Judgement)","ReportType" : "1","ReportShortNameEnum" : "SF Pending STMT"
},
{
"ReportID" : "LEGAL-02","ReportRdlName" : "Suit Filed Account during the Month","ReportType" : "1","ReportShortNameEnum" : "SF During Month"}
}
]
}
How to get "Report_list" from it using JSONSerialization
In jsonResult i received
"eydlcnJvcl9Db2RlJzogJzAnLCdlcnJvcl9tc2cnIDogJ1ZhbGlkIFJlcXVlc3QnLCAnY2FzZV9saXN0JyA6IFt7IkN1c3RvbWVyTmFtZSIgOiAiTVIgQUJISU5BViBTSEFSTUEiLCJjYXNlX2lkIiA6ICIiLCJBZHZJRCIgOiAibml0ZXNoMTIzIiwiU3VpdFR5cGUiIDogIjEiLCJjYXNlX25hbWUiIDogIlN1aXQgLyBBcHBsaWNhdGlvbiIsInNlc3Npb25fSWQiIDogIjQwOTQ5OTg4OSIsIkJyYW5jaENvZGUiIDogIjA0MDgifV19"
In jsonDecryptedString
"{\'error_Code\': \'0\',\'error_msg\' : \'Valid Request\', \'case_list\' : [{\"CustomerName\" : \"MR ABHINAV SHARMA\",\"case_id\" : \"\",\"AdvID\" : \"nitesh123\",\"SuitType\" : \"1\",\"case_name\" : \"Suit / Application\",\"session_Id\" : \"409499889\",\"BranchCode\" : \"0408\"}]}"
And Error is
The data couldn’t be read because it isn’t in the correct format.