zoukankan      html  css  js  c++  java
  • iOS 使用SBJSON创建和解析JSON

    原文地址:http://blog.csdn.net/gf771115/article/details/7718403

    //创建JSON
    NSDictionary *dictonary = [[NSMutableDictionary alloc] init];
    [dictonary setValue:@"MIle" forKey:@"name"];
    [dictonary setValue:@"19" forKey:@"age"];
    [dictonary setValue:@"male" forKey:@"sex"];
    NSDictionary *root = [[NSMutableDictionary alloc] init];
    [root setValue:dictonary forKey:@"player"];

    SBJsonWriter *writer = [[SBJsonWriter alloc] init];
    NSLog(@"Start Create JSON!");
    NSString *value = [writer stringWithObject:root];
    NSLog(value);

    //解析JSON
    NSDictionary *dicRoot = [[[SBJsonParser alloc]init] objectWithString:value];
    for (int i=0; i<[dicRoot count]; i++) {
    NSDictionary *player = [dicRoot objectForKey:@"player"];
    NSString *name = [player objectForKey:@"name"];
    NSString *age = [player objectForKey:@"age"];
    NSString *sex = [player objectForKey:@"sex"];
    NSLog(@"Name = %@", name);
    NSLog(@"Age = %@", age);
    NSLog(@"Sex = %@", sex);

    }

    如果一件事情你觉得难的完不成,你可以把它分为若干步,并不断寻找合适的方法。最后你发现你会是个超人。不要给自己找麻烦,但遇到麻烦绝不怕,更不要退缩。 电工查找电路不通点的最快方法是:分段诊断排除,快速定位。你有什么启示吗? 求知若饥,虚心若愚。 当你对一个事情掌控不足的时候,你需要做的就是“梳理”,并制定相应的规章制度,并使资源各司其职。
  • 相关阅读:
    【[USACO08FEB]酒店Hotel】
    【[USACO15JAN]草鉴定Grass Cownoisseur】
    【[USACO09DEC]牛收费路径Cow Toll Paths】
    【[HAOI2009]逆序对数列】
    【Hankson 的趣味题】
    【开车旅行】
    【[ZJOI2006]物流运输】
    【[HNOI2005]狡猾的商人】
    【愤怒的小鸟】
    【[HNOI2015]菜肴制作】
  • 原文地址:https://www.cnblogs.com/wvqusrtg/p/4554675.html
Copyright © 2011-2022 走看看