gpt4 book ai didi

ios - 如何在 Swift(iOS、Xcode)中将 NSDictionary 转换为 Json 字符串?

转载 作者:IT王子 更新时间:2023-10-29 05:25:25 26 4
gpt4 key购买 nike

<分区>

我遇到了以下问题....我的 NSDictionary 是这样的:

var dic : NSDictionary = [ "level" :
[
["column" : 0,"down" : 0,"left" : 0,"right" : 0,"row" : 0,"up" : 0],
["column" : 1,"down" : 0,"left" : 0,"right" : 0,"row" : 0,"up" : 0],
["column" : 2,"down" : 0,"left" : 0,"right" : 0,"row" : 0,"up" : 0],
["column" : 0,"down" : 0,"left" : 0,"right" : 0,"row" : 1,"up" : 0],
["column" : 1,"down" : 0,"left" : 0,"right" : 0,"row" : 1,"up" : 0],
["column" : 2,"down" : 0,"left" : 0,"right" : 0,"row" : 1,"up" : 0]
]
]

但是如果我打印这个,

print(dic);  or print(“\(dic)”);

输出是这样的:

{
level = (
{
column = 0;
down = 0;
left = 0;
right = 0;
row = 0;
up = 0;
},
{
column = 1;
down = 0;
left = 0;
right = 0;
row = 0;
up = 0;
},
{
column = 2;
down = 0;
left = 0;
right = 0;
row = 0;
up = 0;
},
{
column = 0;
down = 0;
left = 0;
right = 0;
row = 1;
up = 0;
},
{
column = 1;
down = 0;
left = 0;
right = 0;
row = 1;
up = 0;
},
{
column = 2;
down = 0;
left = 0;
right = 0;
row = 1;
up = 0;
}
); }

如何获得准确的 Json 字符串?在 swift 中,xcode?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com