从JSON查找对象



我有一个JSON看起来像这样。

{
  "countrycode" : 
  [["11","","91","INDIA"," New Delhi"],
  ["112","Mahanagar Telephone Nigam Ltd (MTNL]","91","INDIA"," New Delhi"],
  ["113","Reliance Communications Ltd","91","INDIA"," New Delhi"],
  ["114","Bharti Airtel Ltd","91","INDIA"," New Delhi"],
  ["115","Sistema Shyam TeleServices Ltd (MTS]","91","INDIA"," New Delhi"],
  ["122","","91","INDIA"," Hapur  Ghaziabad"],
  ["1222","Bharat Sanchar Nigam Ltd (BSNL]","91","INDIA"," Hapur  Ghaziabad"],
  ["1223","Reliance Communications Ltd","91","INDIA"," Hapur  Ghaziabad"]]
}

我想找到完美的匹配记录,其中一排JSON具有我的价值。我的价值可能是" 1178920"或" 1130123"或" 1151593248"或" 1223798"。

如果我的价值为1223798,则返回我:

["1223","Reliance Communications Ltd","91","INDIA"," Hapur  Ghaziabad"]]

我找不到方法。请帮助我。

NSPredicate *predicateString = [NSPredicate predicateWithFormat:@"ANY SELF BEGINSWITH %@", @"1223"];
NSArray *newarr = [NSMutableArray arrayWithArray:[[dict valueForKey:@"countrycode"] filteredArrayUsingPredicate:predicateString]];

希望这对您有帮助。

获得想要的东西的方式:

Nsarray * object = [NSArray from countrycode]
For (index = 0: index<object; index++ )
{
    NSArray * objectTest = object[index];
    NSString * arrValue = objectTest[0];
   if ([arrValue rangeOfString:@"YourValue"].location == NSNotFound) {
         NSLog(@"string does not contain Value");
   } else {
         NSLog(@"string contains Value!");
   }
} 

最新更新