Php &;json字符串中的amp特殊字符问题

Php &;json字符串中的amp特殊字符问题,php,objective-c,json,url,nsstring,Php,Objective C,Json,Url,Nsstring,我有一个字典数组,它被转换成JSON字符串,如下所示 NSMutableArray *returnArray = [NSMutableArray new]; NSMutableDictionary *temp1= [NSMutableDictionary new]; [temp setObject:@"item1" forKey:@"notes"]; NSMutableDictionary *temp2= [NSMutableDictionary new];

我有一个字典数组,它被转换成JSON字符串,如下所示

 NSMutableArray *returnArray = [NSMutableArray new];

    NSMutableDictionary *temp1= [NSMutableDictionary new];
    [temp setObject:@"item1" forKey:@"notes"];
    NSMutableDictionary *temp2= [NSMutableDictionary new];
    [temp2 setObject:@"item & item2 " forKey:@"notes"];

    NSString *json = [self aryToJSONString:allSync];
[{\"notes\":\" item1 \"},{\"notes\":\"item1 ","item2\"}]":"
json转换器:

-(NSString *)aryToJSONString:(id) ary{

NSError *error; 
NSString *jsonString;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:ary 
                                                   options:0 // Pass 0 if you don't care about the readability of the generated string
                                                     error:&error];

if (! jsonData) {
    NSLog(@"Got an error: %@", error);
} else {
    jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
   }
    return jsonString;
}  
转换的JSON:

[{"notes":"item"},{"notes":"item1 & item2"}]
然后将其发布到服务器(PHP)。服务器接收不可解析的json字符串,如下所示:

 NSMutableArray *returnArray = [NSMutableArray new];

    NSMutableDictionary *temp1= [NSMutableDictionary new];
    [temp setObject:@"item1" forKey:@"notes"];
    NSMutableDictionary *temp2= [NSMutableDictionary new];
    [temp2 setObject:@"item & item2 " forKey:@"notes"];

    NSString *json = [self aryToJSONString:allSync];
[{\"notes\":\" item1 \"},{\"notes\":\"item1 ","item2\"}]":"
我如何处理特殊字符问题

编辑:

PHP代码:

 $json = $_REQUEST['json'];
       $json = stripslashes($json);
       $jsonArr = json_decode($json, true);

       while($item = array_shift($jsonArr))
       {
           foreach($item as $key=>$value)
           {
           }
       }
请尝试以下代码:

在发布到服务器之前,将JSON字符串传递给下面的方法

-(NSString*)replaceSpecialCharsFromString:(NSString*)str
{
    str = [str stringByReplacingOccurrencesOfString:@"&" withString:@"&"];
    str = [str stringByReplacingOccurrencesOfString:@"<" withString:@"&lt;"];
    str = [str stringByReplacingOccurrencesOfString:@">" withString:@"&gt;"];
    return str;
}
-(NSString*)替换SpecialCharsFromString:(NSString*)str
{
str=[str stringByReplacingOccurrencesOfString:@”和“with string:@”和“];
str=[str STRINGBYREPLACINGOURCRENCESOFSTRING:@“with string:@]”;
返回str;
}

尝试像这样使用string replace
str_replace('&','&;',$string)
您可以共享您的php代码吗?php代码共享请检查@Mubashar abbash为什么要使用stripslashes($json)。。在做任何其他事情之前,你是否尝试过回显$json?@Mubashar Abbas我回显了stripslashes($json)之前的json,它会切断“&”符号之后的[{\'notes\':\'item1\'},{\'notes\':\'item1