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);

    }

    如果一件事情你觉得难的完不成,你可以把它分为若干步,并不断寻找合适的方法。最后你发现你会是个超人。不要给自己找麻烦,但遇到麻烦绝不怕,更不要退缩。 电工查找电路不通点的最快方法是:分段诊断排除,快速定位。你有什么启示吗? 求知若饥,虚心若愚。 当你对一个事情掌控不足的时候,你需要做的就是“梳理”,并制定相应的规章制度,并使资源各司其职。
  • 相关阅读:
    b_lc_数组的最大公因数排序(并查集+质因数分解优化)
    Coggle 30 Days of ML:结构化赛题:天池二手车交易价格预测(二)
    Coggle 30 Days of ML:结构化赛题:天池二手车交易价格预测(一)
    漫谈
    漫谈
    漫谈
    漫谈
    漫谈
    漫谈
    漫谈
  • 原文地址:https://www.cnblogs.com/wvqusrtg/p/4554675.html
Copyright © 2011-2022 走看看