2016-04-05 26 views
1

JsonString.txtWie konvertiert man JsonString in String?

{ "Profil": { "name": { "formatiert": "John Jackson", "given": "John", "family": "Jackson"}, „verifiedEmail ":" [email protected] "," googleUserId ":" 1048morenumbers2048 "," displayName ":" John Jackson "," Foto ":" "," preferredUsername ":" rpxstaging "," url ":" "," " providerName ":" Google "," identifier ":" "," birthday ":" 1994-05-19 "," gender ":" weiblich "," email ":" [email protected] "}," accessCredentials " : {"oauthToken": "1/V2UImanylettersandnumbersrnWlVS7c", "oauthTokenSecret": "i5rlettersQU-32moreVY", "Bereiche": "Blogger, Google Kontakte, YouTube, Picasa Web, Alben, Google Kalender, Google Text & Tabellen, Google Mail, Google OpenSocial "," scope ":" "," type ":" OAuth "}," merged_poco ": {" name ": {" formatiert ":" John Jackson "," givenName ":" John ", "Familienname": "Jackson"}, "Adressen": [{"Land": "Vereinigte Staaten"]], "Fotos": [{"Typ": "Anderes", "Wert": ""}], " URLs ": [{" Typ ":" Profil "," Wert ":" "}]," PreferredUsername ":" rpxstaging "," E-Mails ": [{" type ":" other "," value ":" rpxstaging @ gmail.com "}]," languagesSpoken ": [" de-DE "]," id ":" 1048numbers2048 "," displayName ":" John Jackson "," profileUrl ":" "}," stat ":" ok“}

  • ich oben jsonString müssen, um String umgewandelt werden, die unter
  • sieht aus wie

String.txt

{\ "profile \": {\ "name \": {\ "formatiert \": \ "John Jackson \", "givenName": \ "John \", \ "familyName \": \ "Jackson \ "}, \" verifiedEmail \ ": \" [email protected] \ ", \" googleUserId \ ": \" 1048morennumbers2048 \ ", \" \ "\" \ \ \ \ \ \ "John Jackson \", \ "photo \" : \ "\", \ preferredUsername \ ": \" rpxstaging \ ", \" url \ ": \" \ ", \" providerName \ ": \" Google \ ", \" identifier \ ": \" \ "," Geburtstag ":" 1994-05-19 "," Geschlecht ":" weiblich "," Email ":" [email protected] "," accessCredentials " \ ": {\" oauthToken \ ": 1/V2UImanettersandnumbersrnWlVS7c \", \ "oauthTokenSecret \": \ "i5rlettersQU-32moreVY \", \ "scopes \": "Blogger, Google Kontakte, YouTube, Picasa-Webalben , Google Kalender, Google Text & Tabellen, Google Mail, Google OpenSocial \ ", \" scope \ ": \" \ ", \" type \ ": \" OAuth \ "}, \" merged_poco \ ": {\" name \ ": {\" formatiert \ ": \" John Jackson \ "," givenName \ ":" John \ ", \" familyName \ ": \" Jackson \ "}, \" addresses \ ": [{\ "country": \ "United States \"}, \ "photos \": [{"type \": \ "sonstiges \", \ "Wert \" \ ": \" "}}, \" urls \ ": [{\" type \ ": \" profile \ ", \" value \ ": \" \ "}], \" preferredUsername \ ": \ "rpxstaging", "emails": [{"type \": \ "sonstiges \", \ "value \": \ "[email protected] \"}], \ "languagesSpoken \": [ \ "en-US \"], \ "id \": \ "1048numbers2048 \", \ "displayName \": \ "John Jackson \", \ "profileUrl \": \ "\"}, \ "stat \ \ "

  • Kann mir jemand ein pls sagen, wie man konvertiert? Ich bin neu in diesem JSON
+0

Java oder C#? ... – bcsb1001

+0

Mögliches Duplikat von [JS-Objekt in JSON-String konvertieren] (http://stackoverflow.com/questions/4162749/convert-js-object-to-json-string) – thanksd

Antwort

2

Wenn Sie die oben json in einer Textdatei haben, dann können Sie einfach tun:

string strJson = File.ReadAllText("jsonstring.txt"); //Specify the path 

Der erforderliche Wert (zweite json) ist nur die Art und Weise Debugger zeigt es. Sie benötigen wahrscheinlich keine Escape-Werte wie in der tatsächlichen Zeichenfolge.

In Debugger würde es scheinen, als:

enter image description here

+0

für Datei sud i importieren java.io. Datei?Wenn ich dasselbe importiere, bekomme ich einen Fehler bei ReadAllText Sprichwort ** Die Methode ReadAllText (String) ist für den Typ File nicht definiert. –

+0

Der obige Code ist für C#, für Java kann man 'FileUtils' verwenden wie' String strJson = FileUtils. readFileToString ("jsonstring.txt", "utf-8"); 'Weitere Informationen zum Lesen einer Datei in einer String-Variablen finden Sie unter http://stackoverflow.com/questions/3849692/whole-text-file-to-a-string -in-java – Habib

+0

Danke. Das hat für mich funktioniert .. !! –

Verwandte Themen