9
votes

Problème dans la conversion de NSDictionary en chaîne JSON, remplaçant / avec \ /

Je veux convertir NSDictionary en JSON String.Touth tout fonctionne bien, j'ai un petit problème décrit comme suit: J'ai un code suivant pour la conversion de NSDictionary en Nstring: xxx pré>

J'appelle la méthode comme: p> xxx pré>

suivi est la sortie de la sortie de CE NSLOG: P>

{
      "hello" : "21/11/2014 10:07:42 AM"
}


1 commentaires

Y a-t-il quelque chose qui ne va pas si vous appelez simplement la méthode description sur le dictionnaire?


5 Réponses :


0
votes

convertir l'objet JSON en chaîne échappera à la barre oblique vers l'avant. C'est pourquoi la barre oblique arrière est ajoutée dans votre résultat.

Si vous convertissez la chaîne Retour à l'objet JSON et enregistré l'objet, vous pouvez voir le résultat comme prévu. Ainsi, vous pouvez vérifier, il n'y a rien de mal avec la chaîne.


0 commentaires

0
votes

0 commentaires

2
votes

Essayez ceci,

NSData *json = [NSJSONSerialization dataWithJSONObject:dict
                                               options:0
                                                 error:&error];
NSString *jsonString = [[NSString alloc] initWithData:json encoding:NSUTF8StringEncoding];
// This will be the json string in the preferred format 
jsonString = [jsonString stringByReplacingOccurrencesOfString:@"\\/" withString:@"/"];

// And this will be the json data object 
NSData *processedData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];


0 commentaires

22
votes

nsdictionary - à - chaîne forte> xxx pré>

string - to - NSDictionary strong> p>

NSError * err;
NSDictionary * response = (NSDictionary *)[NSJSONSerialization JSONObjectWithData:[NSData dataFromString:str] options:NSJSONReadingMutableContainers error:&err];


0 commentaires

1
votes

Convertir en réponse aux données avec option jolie imprimée, puis convertissez les données en chaîne à l'aide de l'encodage UTF8 Code: xxx


1 commentaires

Toute réponse qui obtient l'administrateur qui passe dans la bonne direction est utile, mais essayez de mentionner toutes les limitations, hypothèses ou simplifications dans votre réponse. La brièveté est acceptable, mais des explications plus complètes sont meilleures.