gpt4 book ai didi

ios - NSString stringWithFormat objectForKey自定义Json数据

转载 作者:行者123 更新时间:2023-12-01 18:08:48 29 4
gpt4 key购买 nike

此代码在名为username的UILabel中显示了用户的caption

caption.text = [NSString stringWithFormat:@"@%@",[data objectForKey:@"username"]];

我希望 caption代替显示该用户的 device token而不是其 username。到目前为止,这是 device token在应用程序中成功使用的方式。
//A different Method that successfully handles the device token
NSMutableDictionary* params =[NSMutableDictionary dictionaryWithObjectsAndKeys:command, @"command", [_dataModel deviceToken], @"token", nil ];


//Another different method that successfully handles the device token with a slightly different syntax
NSDictionary *params = @{@"cmd":@"join",
//the red text passes user_id to _datamodels userId method and thusly to api.php's handleJoin function
@"token":[_dataModel deviceToken],
};

问题:如何为 objectforkey值编写正确的语法以显示 token ?这是我尝试过的方法,但收到编译器警告: no visible interface declaration for selector objectForKey。我知道这可以做到,怎么办?
caption.text = [NSString stringWithFormat:@"@%@",[data objectForKey:@"token":[_dataModel deviceToken]]];

原始儿子:数据
//Method body
-(id)initWithIndex:(int)i andData:(NSDictionary*)data
{
self = [super init];
if (self !=nil)
{

最佳答案

试试这个:

caption.text = [NSString stringWithFormat:@"%@", data[@"username"][@"token"]];

关于ios - NSString stringWithFormat objectForKey自定义Json数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35916406/

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