var dict1=Dictionary<String,AnyObject>()
dict1["name"]="Jack"
dict1["age"]=16
dict1["nickname"]=nil
println(dict1) //"[age: 16, name: Jack]"
let jsonData1 = NSJSONSerialization.dataWithJSONObject(dict1, options: NSJSONWritingOptions.allZeros, error: nil)!
let jsonString1 = NSString(data: jsonData1, encoding: NSUTF8StringEncoding)!
println(jsonString1) //"{"age":16,"name":"Jack"}"
如果像要字典的值为NULL,可以使用NSNULL,这样就可以达到像要的效果了:
var dict2=Dictionary<String,AnyObject>()
dict2["name"]="Jack"
dict2["age"]=16
dict2["nickname"]=NSNull()
println(dict2) //[age: 16, nickname: <null>, name: Jack]
let jsonData2 = NSJSONSerialization.dataWithJSONObject(dict2, options: NSJSONWritingOptions.allZeros, error: nil)!
let jsonString2 = NSString(data: jsonData2, encoding: NSUTF8StringEncoding)!
println(jsonString2) //{"age":16,"nickname":null,"name":"Jack"}
String seatname="set"+i+""+jSeat seat
seat= new Seat(Seatsname, "green", 0)
seats.Add(seat.SeatName, seat)
改成 String seatname="set"+i+""+j
seats.Add(SeatName, new Seat(Seatname, "green", 0))
对啦,seat= new Seat(Seatsname, "green", 0)中Seatsname应该是笔误吧,我修改为Seatname
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)