更改JSON字符串格式

时间:2013-05-13 05:53:34

标签: objective-c json

如何更改以下JSON结构,

[
    "registerDevice",
    {
        "type": "7",
        "pushBadge": "1",
        "pushSound": "1",
        "enabled": "1",
        "deviceToken": "e03d25f4f1bd40678cd693fe66fe7946ffdb03e1b23cfc5f9dc747fd5869fbcd",
        "pushAlert": "1"
    }
]

使用Objective-c

的格式
  

@" [\" registerDevice \" {\"类型\":\" 7 \" \&#34 ; pushBadge \":\" 1 \" \" pushSound \":\" 1 \" \"当使能\":\" 1 \" \" deviceToken \":\" e84ab955cd3b9af439f1567b9f80e70d52d3b0209151fe9b3392efc8af9f5e1f \" \" pushAlert \& #34;:\" 1 \"}]&#34 ;;

2 个答案:

答案 0 :(得分:1)

尝试这样,

yoursting=[yourstring stringByReplacingOccurrencesOfString@"\"" withString:@"\\\""];

答案 1 :(得分:0)

试试这个

- (NSUInteger)replaceOccurrencesOfString:(NSString *)target withString:(NSString *)replacement options:(NSStringCompareOptions)opts range:(NSRange)searchRange