我在iPhone上App.I工作必須JSON字符串返回到Web服務在以下格式從Iphone.I我使用Objective-CiPhone:如何在目標C創建JSON
{
"InspectionDetails":
[
{"isCompleted":"Y","QMSStepId":"1A","QMSEmpId":"6","QMSInspectionID":"1","InspectedDate":"07/28/11 09:52:34", "isNewRoom":"1","RoomInspID":"1","QMSRoomId":"1","QMSScoreId":"4"},
{"isCompleted":"Y","QMSStepId":"1B","QMSEmpId":"4","QMSInspectionID":"1","InspectedDate":"07/28/11 09:52:34", "isNewRoom":"1","RoomInspID":"1","QMSRoomId":"1","QMSScoreId":"3"}
],
"InspectionComments":
[
{"QMSPredefinedCommentId":"1","customText":"Test1 Comment","RoomInspID":"1"},
{"QMSPredefinedCommentId":"2","customText":"Test2 Comment","RoomInspID":"1"}
],
"Tools":
[
{"Facility_Code" : "1","HddId" : "AIPH01"}
]
}
任何一個可以請幫助我如何形成上述迴應?
我有一個想法,我可以通過使用NSArray和NSDictonary來做到這一點,但我想在一本字典中的所有數組。任何人都可以請指導?
感謝, Shradha
嗨cduhn.But我有3個字典objects.From上面的字符串,你可以看到一個爲「InspectionDetails」,一個爲「InspectionComments」,一個爲「工具」。我可以將這3個字典對象放入一個並使用JsonValue。我怎麼能夠? –
這只是包含3個數組的1個字典對象。只需在頂級字典中調用JSONRepresentation即可。它將遞歸地將該字典中的所有對象序列化爲它們的JSON表示形式。 – cduhn
嗨cduhn.Sorry,但我必須形成以上格式的json字符串。 我的查詢是我將如何能夠從3數組中創建以上格式的json字符串。我有3個單獨的數組和鍵,並從中創建一個字典。你可以幫忙嗎? –