我是初學者在ios和我的一個活動:這是我的nsstring,現在我想從這個字符串獲取「LocationId」,但我有問題.....我嘗試在數組中添加此字符串,之後得到LocationId但我也有錯誤....如何從ios中獲取Nsstring的值?
Nsstring *Str={"UserName":"ankitdemo","UserId":"08f11980-9920-4127-8fe7-78e1c40f6002","RoleName":"Doctor","RoleId":"87b4193c-1252-4505-a81b-2b49b8db57f3","FirstName":"Ankit","MiddleName":"","LastName":"Gupta","LocationId":"5f15648f-12ef-4534-a145-4044bc7c742e"}
Nsstring *LocationId=[NSString stringWithFormat:@"%@",[Str valueForKey:@"LocationId"]];
OR
NSMutableArray *location =[[NSMutableArray alloc]init];
[location addObject:self.WebService.ptr];
NSLog(@"location id is %@",location);
LocationId=[NSString stringWithFormat:@"%@",[[location objectAtIndex:0]valueForKey:@"LocationId"]];
NSLog(@"location id is %@",LocationId);
,但我有錯誤....
ERROR
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSCFString 0x881d6d0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key LocationId.'
Solve this problem.......
請出示您的真實代碼。前兩行永遠不會編譯。 –