将JSON数据存储为字符串目标C.

时间:2016-08-03 16:36:14

标签: objective-c json

所以我得到了我的Json数据:

import csv

with open('registrant_data.csv') as csvFile:
    readCSV = list(csv.DictReader(csvFile))

with open('nametags8gen.html', 'w+') as myWriteFile:
    myWriteFile.write('<!DOCTYPE html> \n'
                      '<html>\n'
                      '<head>\n'
                      '<title>natetag8</title>\n'
                      '<link href="styles/nametags8.css" type="text/css" rel="stylesheet" />\n'
                      '</head>\n'
                      '<body>\n'
                      '<header>\n'
                      '</header>\n'
                      '<main class="mainContainer">\n'
                      '<div class"textBoxContainer">\n'
                      '<div class="textContainer">\n')


    for row in readCSV:
        myWriteFile.write('<span class="font22">' + row['firstname'] +'</span>\n'
                          '<span class="font12">' + row['lastname'] +'</span>\n'
        # here add other info for each person

    myWriteFile.write('</div>\n'
                      '</body>\n')

我正在尝试将该个人名称存储为字符串。

{
"name": "brad"
}

但是当我打印出json文件时,我得到上面显示的内容,我是否需要使用分隔符或其他东西来获取此字符串?

由于

1 个答案:

答案 0 :(得分:2)

实际上,JSON是一个字典而不是一个数组,并且nilOptions不可变。

brad

NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSString *name = json[@"name"];
NSLog(@"name: %@", name);