gpt4 book ai didi

java - 如何将 JsonString 转换为 String?

转载 作者:行者123 更新时间:2023-11-30 02:58:55 26 4
gpt4 key购买 nike

JsonString.txt

{ "profile": { "name": { "formatted": "John Jackson", "givenName": "John", "familyName": "Jackson"}, "verifiedEmail": "rpxstaging@gmail.com ", "googleUserId": "1048morenumbers2048", "displayName": "约翰· jackson ", "照片": "", "preferredUsername": "rpxstaging", "url": "", "providerName": "Google","标识符": "", "生日":"1994-05-19", "性别":"女", "电子邮件": "rpxstaging@gmail.com"}, "accessCredentials":{ "oauthToken":"1/V2UImanylettersandnumbersrnWlVS7c", "oauthTokenSecret":"i5rlettersQU-32moreVY", "范围": "Blogger、Google 通讯录、YouTube、Picasa 网络、相册、Google 日历、Google 文档、Google Mail、Google OpenSocial", "范围":"", "type":"OAuth"}, "merged_poco": { "name": { "formatted": "John Jackson", "givenName": "John", "familyName": "Jackson"}, "addresses": [ { "country": "United States"} ], "photos": [ { "type": "other", "value": ""} ], "urls": [ { "type": "profile", "value": ""} ], "preferredUsername": "rpxstaging", "emails": [ { "type": "other", "value": "rpxstaging@gmail.com"} ], "lingualsSpoken": [ "en-US"], "id":"1048numbers2048", "displayName": "John Jackson", "profileUrl": ""}, "stat": "ok"}

  • 我需要将上面的 jsonString 转换为如下所示的字符串

字符串.txt

{\"个人资料\": {\"姓名\": {\"格式化\":\"约翰· jackson \",\"givenName\":\"约翰\",\"familyName\":\“ jackson \”},\“验证电子邮件\”:\“rpxstaging@gmail.com\”,\“googleUserId\”:\“1048morenumbers2048\”,\“显示名称\”:\“约翰· jackson \”,\“照片\":\"\"、\"preferredUsername\":\"rpxstaging\"、\"url\":\"\"、\"providerName\":\"Google\"、\"identifier\":\"\",\"生日\":\"1994-05-19\",\"性别\":\"女\",\"电子邮件\":\"rpxstaging@gmail.com\"},\"accessCredentials\":{\"oauthToken\":\"1/V2UImanylettersandnumbersrnWlVS7c\",\"oauthTokenSecret\":\"i5rlettersQU-32moreVY\",\"scopes\":\"Blogger、Google 通讯录、YouTube、Picasa网络相册、Google 日历、Google 文档、Google Mail、Google OpenSocial\",\"范围\":\"\",\"类型\":\"OAuth\"},\"merged_poco\": {\"姓名\": {\"格式化\":\"约翰· jackson \",\"givenName\":\"约翰\",\"familyName\":\" jackson \"},\"地址\": [ {\"国家\":\"美国\"} ],\"照片\": [ {\"类型\":\"其他\",\"值\":\""} ],\"urls\": [ {\"type\":\"profile\",\"value\":\"\"} ],\"preferredUsername\":\"rpxstaging\",\"emails\": [ {\"type\":\"other\",\"value\":\"rpxstaging@gmail.com\"} ],\"lingualsSpoken\": [\"en- US\"],\"id\":\"1048numbers2048\",\"displayName\":\"John Jackson\",\"profileUrl\":\"\"},\"stat\":\"好的\"}

  • 有人可以告诉我如何转换吗?我是这个 JSON 的新手

最佳答案

如果您在文本文件中有上述 json,那么您可以简单地执行以下操作:

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

所需的值(第二个json)正是调试器显示它的方式。您可能不需要像实际字符串中那样的转义值。

在调试器中它将显示为:

enter image description here

关于java - 如何将 JsonString 转换为 String?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36430368/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com