我正在通過Web服務接收阿拉伯數據。我將數據作爲JSON對象獲得,但是當我將值傳遞給NSDictionary
時,它顯示nil
並且無法獲得key/pair
value.i接收值直到data
,但我無法將其傳遞給NSDictionary
。NSDictionary在IOS中顯示爲零/目標c
下面是代碼:
(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
for (NSString *key in [json allKeys])
{
NSArray *feed = [json objectForKey:key];
for(int i=0; i<feed.count;i++)
{
for (NSString *key1 in [[feed objectAtIndex:i] allKeys])
{
if([key1 isEqualToString:@"newsTitle"])
{
NSString *value = [[feed objectAtIndex:i] objectForKey:key1];
[NewsTitleArray addObject:value];
}
else if([key1 isEqualToString:@"newsDescription"])
{
NSString *value = [[feed objectAtIndex:i] objectForKey:key1];
[NewsDescriptionArray addObject:value];
}}}}
您從服務器接收到的JSON值是否可能不是字典或可能包含使其成爲無效JSON字符串的其他字符?你還可以請包括從服務器收到的JSON字符串? –
@Chonch我檢查字符串使用jsonlint.com/ ..它說這是驗證JSON..thnx – jithin