gpt4 book ai didi

objective-c - 如何使用 NSString 解析这个字符串?

转载 作者:行者123 更新时间:2023-12-03 17:29:44 25 4
gpt4 key购买 nike

我有以下字符串:

callback({"Outcome":"Success", "Message":null, "Identity":"Request", "Delay":0.002, "Symbol":"AAPL", "CompanyName":"Apple Inc.", "Date":"1\/13\/2011", "Time":"4:02:36 PM", "Open":344.6, "Close":345.93, "PreviousClose":344.42, "High":346.63, "Low":343.86, "Last":345.93, "Change":1.51, "PercentChange":0.438, "Volume":785960})

我希望我的最终字符串不包含字符串末尾的 callback( 和最后一个 ) 。我怎样才能修改这个NSString?

最佳答案

NSScanner 非常适合此类事情。

NSString *json = nil;
NSScanner *scanner = [NSScanner scannerWithString:fullString];
[scanner scanUpToString:@"{" intoString:NULL]; // Scan to where the JSON begins
[scanner scanUpToString:@")" intoString:&json];

NSLog(@"json = %@", json);

关于objective-c - 如何使用 NSString 解析这个字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4686459/

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