好,我需要按以下方式解析收到的数据:
[
{
“IdEmpleado”:1,
“农布雷”: “塞萨尔”,
“EDAD”: “25”,
“的Genero”: “M”,
“IdArea”:1个
},
{
“IdEmpleado”:2,
“农布雷”: “路易斯”,
“EDAD”: “30”,
“的Genero”: “M”,
“IdArea”:2
}
]
我需要获取每位员工的数据,例如,2名员工需要每个对象的所有字段,然后将其转换为员工。谢谢你的帮助。
我已经使用了JSON并转移到了NSDICTIONARY,但是如何让它结构化以便每个字段并且能够传递一个方法来转换对象EMPLOYEE?
答案 0 :(得分:4)
答案 1 :(得分:4)
您可以使用JSONFramework,您可以在此处找到。
答案 2 :(得分:1)
NSString *userid= [[NSUserDefaults standardUserDefaults]objectForKey:@"Userid"];
NSString *appurl =[NSString stringWithFormat:@"your link"];
appurl = [appurl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:appurl]];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse: nil error: nil ];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding: NSUTF8StringEncoding];
NSMutableDictionary *deletdict=[returnString JSONValue];
if([[deletdict objectForKey:@"success"] isEqualToString:@"False"])
{
NSLog(@"Unsuccess...");
}
else
{
NSLog(@"success...");
}
AND Post method is this
NSString *post =[NSString stringWithFormat:@"AgencyId=STM&UserId=1&Type=1&Date=%@&Time=%@&Coords=%@&Image=h32979`7~U@)01123737373773&SeverityLevel=2",strDateLocal,strDateTime,dict];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://174.94.153.48:7778/TransitApi/IncidentConfirm/"]]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSError *error;
NSURLResponse *response;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *str=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
NSMutableArray *SubLiveArray=[str JSONValue];
download Json framework on this link:::
http://mobile.tutsplus.com/tutorials/iphone/iphone-json-twitter-api
NSString *appurl=[NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/search/json?location=23.041230,72.514346&radius=50000&types=%@&sensor=true&key=AIzaSyAQZ16VzshxGbYdiM8C2RhhwGl3QwVJTB4",_txt_search.text];