gpt4 book ai didi

objective-c - 想要从 URL 而不是响应中拆分 JSON

转载 作者:行者123 更新时间:2023-11-29 13:46:40 24 4
gpt4 key购买 nike

我想在我的 iPhone 应用程序中从这个 URL 中拆分 json 部分。

http://vkontakte.ru/login_success.html#session={"expire":"1272008089","mid":"100172","secret":"9c8d8f0305","sid":"1131703552161ae352a1256402e3140d7cbde41b1602a93d15472c82"}

我试过并将 JSON 保存到 NSString 中,但我得到的是

http://vkontakte.ru/api/login_success.html?session=%7B%22mid%22:113158415,%22secret%22:%227ce58bfcd3%22,%22sid%22:%2203831b43c1bb992f9477efbfe96e83f6ecff1c1 b661315ac0a20719cf57a44%22 ,%22expire%22:0%7D

这不是 JSOn 格式。下面是我的代码

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {

NSURL *url = [request URL];
NSError* error;
NSLog (@"json path %@",url);
SBJsonParser *parser = [[SBJsonParser alloc] init];
NSURLRequest *request1 = [NSURLRequest requestWithURL:url];
NSString *json_string = [url absoluteString];
NSArray *arr = [json_string componentsSeparatedByString:@"="];
json_string = [arr objectAtIndex:1];
// parse the JSON response into an object
// Here we're using NSArray since we're parsing an array of JSON status objects
NSArray *statuses = [json_string JSONValue];

NSLog(@"%@",error);

// Each element in statuses is a single status
// represented as a NSDictionary
for (NSDictionary *status in statuses)
{
// You can retrieve individual values using objectForKey on the status NSDictionary
// This will print the tweet and username to the console
NSLog(@"%@ - %@", [status objectForKey:@"secret "], [[status objectForKey:@"mid"] objectForKey:@"sid"]);
}
return YES;
}

如何才能走得更远?

最佳答案

尝试替换:

NSString *json_string = [url absoluteString];

NSString *json_string = [[url absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

不过,你所做的事情确实很奇怪。为什么 URL 中包含 JSON?

关于objective-c - 想要从 URL 而不是响应中拆分 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7125240/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com