删除 JSON 响应中的第一行
Remove first line in JSON response
我正在非正式地使用 Google 演讲 API。如果你向它发送一个音频文件说 "Test",它会这样回应:
{"result":[]}
{"result":[{"alternative":[{"transcript":"test","confidence":0.88845605},{"transcript":"tests"},{"transcript":"the test"},{"transcript":"text"},{"transcript":"Test"}],"final":true}],"result_index":0}
我需要删除此响应的第一行,这样我的解析器就不会出错。
是否有官方方法删除 JSON 中的第一行?
我正在使用 Xcode 6.1(我还没有更新 Xcode)和 iOS 6.1 SDK。
NSString* fileRoot = [[NSBundle mainBundle]
pathForResource:@"test" ofType:@"txt"];
NSString* fileContents = [NSString stringWithContentsOfFile:fileRoot
encoding:NSUTF8StringEncoding error:nil];
NSArray* allLinedStrings = [fileContents componentsSeparatedByCharactersInSet:
[NSCharacterSet newlineCharacterSet]];
这个数组中可以判断是否包含电话号码,str
是每一个元素
NSString *phoneNumber = [str componentsSeparatedByString:@":"][1];
如果电话号码是电话号码格式。然后删除这一行。
// Assuming your string looks something like this
NSString *fileContents = @"Bob Smith: 1 (234)-567-8901\nBob Smith: bob@bob.com";
// Lets store the information on each new line in an array
NSArray *lines = [fileContents componentsSeparatedByString:@"\n"];
// The second object will contain the email
NSString *email = [lines objectAtIndex:1];
NSLog(@"%@",email);
我正在非正式地使用 Google 演讲 API。如果你向它发送一个音频文件说 "Test",它会这样回应:
{"result":[]}
{"result":[{"alternative":[{"transcript":"test","confidence":0.88845605},{"transcript":"tests"},{"transcript":"the test"},{"transcript":"text"},{"transcript":"Test"}],"final":true}],"result_index":0}
我需要删除此响应的第一行,这样我的解析器就不会出错。
是否有官方方法删除 JSON 中的第一行?
我正在使用 Xcode 6.1(我还没有更新 Xcode)和 iOS 6.1 SDK。
NSString* fileRoot = [[NSBundle mainBundle]
pathForResource:@"test" ofType:@"txt"];
NSString* fileContents = [NSString stringWithContentsOfFile:fileRoot
encoding:NSUTF8StringEncoding error:nil];
NSArray* allLinedStrings = [fileContents componentsSeparatedByCharactersInSet:
[NSCharacterSet newlineCharacterSet]];
这个数组中可以判断是否包含电话号码,str
是每一个元素
NSString *phoneNumber = [str componentsSeparatedByString:@":"][1];
如果电话号码是电话号码格式。然后删除这一行。
// Assuming your string looks something like this
NSString *fileContents = @"Bob Smith: 1 (234)-567-8901\nBob Smith: bob@bob.com";
// Lets store the information on each new line in an array
NSArray *lines = [fileContents componentsSeparatedByString:@"\n"];
// The second object will contain the email
NSString *email = [lines objectAtIndex:1];
NSLog(@"%@",email);