Mysql 根据用户id显示JSON内容

Mysql 根据用户id显示JSON内容,mysql,ios,objective-c,json,Mysql,Ios,Objective C,Json,我想根据用户id显示内容。 用户登录到应用程序,成功登录后,他将根据从连接到外部mysql数据库的JSON文件检索到的id查看内容 我的问题是: 如何使(user\u id=1)中的“1”动态,在某种程度上,当用户登录到他的帐户时,它将自动更改。动态准备URL NSString *userID = @"23";//Get your userID after login NSURL *jsonURL = [NSURL URLWithString:[NSString stringWithFormat

我想根据用户id显示内容。 用户登录到应用程序,成功登录后,他将根据从连接到外部mysql数据库的JSON文件检索到的id查看内容

我的问题是:


如何使(user\u id=1)中的“1”动态,在某种程度上,当用户登录到他的帐户时,它将自动更改。

动态准备URL

NSString *userID = @"23";//Get your userID after login
NSURL *jsonURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://api.example.com/page.php?user_id=%@",userID];

您可以使用NSString类的
StringWithFormat
方法,该方法帮助您创建动态NSString对象

    - (void)viewDidLoad
    {
    [super viewDidLoad];
    NSString userId = @"your user id here";
    NSURL *jsonURL = [NSURL URLWithString:[NSString StringWithFormat:@"http://api.example.com/page.php?user_id=%@",userId]];
    NSData *jsonData = [NSData dataWithContentsOfURL:jsonURL];
    NSError *error = nil;
    NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
    NSLog(@"%@",dataDictionary);
    self.something = [dataDictionary objectForKey:@"something"];
   }

你只是在问如何动态创建URL字符串吗?事实上,我是iOS开发的新手,我想根据我的需要,我的问题非常清楚。所以,如果你能帮助我,你会为我节省很多时间!无论如何谢谢你!谢谢你的回答!谢谢你的回答!
    - (void)viewDidLoad
    {
    [super viewDidLoad];
    NSString userId = @"your user id here";
    NSURL *jsonURL = [NSURL URLWithString:[NSString StringWithFormat:@"http://api.example.com/page.php?user_id=%@",userId]];
    NSData *jsonData = [NSData dataWithContentsOfURL:jsonURL];
    NSError *error = nil;
    NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
    NSLog(@"%@",dataDictionary);
    self.something = [dataDictionary objectForKey:@"something"];
   }