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: J'appelle la méthode comme: p> suivi est la sortie de la sortie de CE NSLOG: P> {
"hello" : "21/11/2014 10:07:42 AM"
}
5 Réponses :
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. P>
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. P>
Ajoutez ceci renvoyer ce générer une chaîne JSON de Nsdictionnaire dans iOS P> P>
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];
nsdictionary - à - chaîne forte> string - to - NSDictionary strong> p> NSError * err;
NSDictionary * response = (NSDictionary *)[NSJSONSerialization JSONObjectWithData:[NSData dataFromString:str] options:NSJSONReadingMutableContainers error:&err];
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:
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.
Y a-t-il quelque chose qui ne va pas si vous appelez simplement la méthode code> description code> sur le dictionnaire?