iOS 中json中字典 轉json格式字串

2021-07-10 02:38:28 字數 726 閱讀 6022

這是我從plist檔案中找到的乙個字典,把裡面的字典轉成了json資料,多注意字串的拼接,雖然不難,容易犯錯誤。

-(nsarray *)flags

nsmutablestring *jsonstring=[nsmutablestring

stringwithformat:mutstr];

[jsonstring insertstring:@"["

atindex:0];

[jsonstring insertstring:@"]"

atindex:jsonstring.length-1];

nsstring *subjson=[jsonstring substringtoindex:jsonstring.length-1];

nslog(@"%@",subjson);

}return

_flags;

}後面這個類方法我自己新建了乙個類檔案放進去了,類名就是

dicttojson.h 和 

dicttojson.m ,

這個方法不知道是誰寫的,我直接複製過來,很好用的

+ (nsstring*)dictionarytojson:(nsdictionary *)dict

///*******下面這些是列印結果*********/////

[,,,,,,,,,,,,,,,]

iOS 陣列 字典轉json

nsmutablearray temparr nsmutablearray array 這裡不要用for in 先找到模型,然後給可變字典賦值,最後裝到陣列裡 nsmutabledictionary dic nsmutabledictionary dictionary for int i 0 i s...

json 轉字典 字典轉json

brief 把格式化的json格式的字串轉換成字典 param jsonstring json格式的字串 return 返回字典 json格式字串轉字典 nsdictionary dictionarywithjsonstring nsstring jsonstring nsdata jsondata...

ios 字典轉模型

property nonatomic,copy nsstring name property nonatomic,copy nsstring icon 例項化 instancetype initwithdic nsdictionary dic 類方法可以快速例項化乙個模型 end m檔案 字典例項化...