我有一个JSON
对象,它有一个像这样的键值对
"AttachedDocument": "[{\"DocumentId\":354,\"DocumentName\":\"Screenshot_2016-04-15-00-35-11.png\",\"DocumentType\":\"image/png\"}]"
此值以字符串形式出现。如何将其转换为NSArray
完整对象
{
"LeaveEntryCode": 0,
"RequestId": 0,
"EmployeeCode": 17186,
"LeaveYear": 2016,
"LeaveTypeCode": 1,
"LeaveReasonCode": 0,
"BaseType": "ess",
"StartDate": "2016-10-24T00:00:00",
"EndDate": "2016-10-24T00:00:00",
"NoOfDays": 1,
"StartDateSession": "full",
"EndDateSession": "full",
"PreApproved": false,
"ForDate": "1901-01-01T00:00:00",
"Remarks": "test from Android",
"CoveringPersonCode": 0,
"AttachedDocument": "[{\"DocumentId\":354,\"DocumentName\":\"Screenshot_2016-04-15-00-35-11.png\",\"DocumentType\":\"image/png\"}]",
"RequestStatus": "P",
"Deleted": false,
"Status": false,
"CreatedBy": 0,
"CreatedDate": "0001-01-01T00:00:00",
"UpdatedBy": 0,
"UpdatedDate": "0001-01-01T00:00:00",
"DeletedBy": 0,
"DeletedDate": "0001-01-01T00:00:00",
"ModuleId": 2,
"ObjectId": 20,
"StartDateString": "10/24/2016",
"EndDateString": "10/24/2016",
"LeaveDayList": [
"10/24/2016-FH,10/24/2016-SH"
],
"SystemLeaveTypeCode": "ANN",
"LeaveTypeName": "ANNUAL",
"Employee": null,
"LieuDayList": null,
"BaseLeaveType": "ANN",
"CoveringPersonName": null,
"LeaveReasonName": "test",
"DocumentSource": "LEAVE"
}
这是我正在获取的完整JSON
对象。我通过网络服务得到这个。
答案 0 :(得分:1)
实际上,您获得%>%
作为回复,因此您可以将其转换为josn string
之类的内容,
josn object
此处 NSString *yourString = @"[{\"DocumentId\":354,\"DocumentName\":\"Screenshot_2016-04-15-00-35-11.png\",\"DocumentType\":\"image/png\"}]";
NSError *error;
NSData *data = [yourString dataUsingEncoding:NSUTF8StringEncoding];
NSArray *jsonObject = [NSJSONSerialization JSONObjectWithData:data
options:NSJSONReadingMutableContainers
error:&error];
NSLog(@"json object : %@",jsonObject);
表示yourString
键的对象!