iPhone Google Data API HTTP协议,来自字符串的身份验证令牌 [英] iPhone Google Data API HTTP Protocol, Auth Token from string
问题描述
SID =东西...
LSID =东西...
认证=长授权令牌
如果我它存储在NSString中,在Auth后面调整到=的最佳功能是什么,并保留其余部分?
NSData * returnedData = [NSURLConnection sendSynchronousRequest:request returningResponse:theResponse error:NULL];
NSString * newDataString = [[NSString alloc] initWithData:returnedData encoding:NSUTF8StringEncoding];
NSString * authToken = [newDataString ____________];
我通过文档自己找出答案对于NSString:
有一个名为
- (NSArray *)的方法componentsSeparatedByCharactersInSet:(NSCharacterSet *)separator {
返回一个由NSCharacterSet分隔的不同字符串的数组。
有一个名为
的的NSCharacterSet类方法
+(NSCharacterSet *)newLineCharacterSet {
将会将带有换行符的字符串拆分成小块,所以每行都会变成自己的对象。这是它是如何工作的:
NSData * returnedData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:NULL];
NSString * newDataString = [[NSString alloc] initWithData:returnedData encoding:NSUTF8StringEncoding];
NSCharacterSet * theCharacterSet = [NSCharacterSet newlineCharacterSet];
NSArray * lineArray = [newDataString componentsSeparatedByCharactersInSet:theCharacterSet];
现在,对象lineArray包含不同的字符串,每个字符串都是新行的开始。 p>
不客气!
Google Docs returns a long 3 line string when supplied with credentials. This is the format SID=stuff... LSID=stuff... Auth=long authorization token
if I have it stored in NSString, what is the best function to trim all the way up to the "=" behind Auth, and keep the rest?
NSData *returnedData = [NSURLConnection sendSynchronousRequest:request returningResponse:theResponse error:NULL];
NSString *newDataString = [[NSString alloc]initWithData:returnedData encoding:NSUTF8StringEncoding];
NSString *authToken = [newDataString ____________];
I figured out the answer on my own through the documentation for NSString:
there is a method called -(NSArray *)componentsSeparatedByCharactersInSet:(NSCharacterSet *)separator {
that gives back an array of different strings, separated by an NSCharacterSet.
There is a class method of NSCharacterSet called
+(NSCharacterSet *)newLineCharacterSet {
that will split up a string with the newline symbol into pieces, so each line becomes its own object. Here is how it works:
NSData *returnedData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:NULL];
NSString *newDataString = [[NSString alloc]initWithData:returnedData encoding:NSUTF8StringEncoding];
NSCharacterSet *theCharacterSet = [NSCharacterSet newlineCharacterSet];
NSArray *lineArray = [newDataString componentsSeparatedByCharactersInSet:theCharacterSet];
Now, the object lineArray contains different strings, each one is the start of a new line.
You're welcome!
这篇关于iPhone Google Data API HTTP协议,来自字符串的身份验证令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!