在目标C中创建一个json字符串 [英] Create a json string in objective C
问题描述
我必须动态生成一个json字符串,并且需要发送到服务器。是否有人知道如何使用 NSJSONSerialization
。以下是我的字符串
I have to generate a json string dynamically and need to send to the server. Is any body know how to do it using NSJSONSerialization
. Below is my string
{
"surveyid": "Survey1",
"responsetime": "dd/mm/yyyy hh:mm:ss",
"location": null,
"surveyresponses": [
{
"questionid": "111",
"responses": [
{
"response": "Good",
"optionid": 1,
"language": "en"
}
]
},
{
"questionid": "112",
"responses": [
{
"response": "bad",
"optionid": 2,
"language": "en"
}
]
}
]
}
如何创建string.json,如果有人知道,请提供帮助。在此先感谢。
How can create a string.json , Please help if any one know. Thanks in advance.
推荐答案
我完全同意@Apurv,
其实@Paras Joshi给你的实际答案问题...(如何发送)
i totally agree with @Apurv, actually @Paras Joshi give the actual answer to your question...(how to send)
NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
[dict setValue:@"Survey1" forKey:@"surveyid"];
[dict setValue:@"responsetime" forKey:@"dd/mm/yyyy hh:mm:ss"];
.
.
.
然后数组 forKey @surveyresponses
...再次创建一个字典... bla..bla
and then an array forKey @"surveyresponses"
... in it again create a dictionary...bla..bla
请先说清楚你最想要的...如何发送一个JSON字符串/如何生成JSON值。
Please make it clear first what you exactly want... How to send a JSON string / how to generate a JSON value.
学会接受答案并完美分析答案,并明确问题。
learn to accept the answers as well as analyse the answers perfectly, and make your questions clear.
这篇关于在目标C中创建一个json字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!