gpt4 book ai didi

c# - 如何在代码中写入 JSON 字符串值?

转载 作者:IT王子 更新时间:2023-10-29 04:52:11 26 4
gpt4 key购买 nike

我想将以下字符串存储在一个字符串变量中

{"Id":"123","DateOfRegistration":"2012-10-21T00:00:00+05:30","Status":0}

这是我使用的代码..

String str="{"Id":"123","DateOfRegistration":"2012-10-21T00:00:00+05:30","Status":0}";

.. 但它显示错误..

最佳答案

你必须这样做

String str="{\"Id\":\"123\",\"DateOfRegistration\":\"2012-10-21T00:00:00+05:30\",\"Status\":0}";


see this for reference
还有from msdn :)

Short Notation  UTF-16 character    Description
\' \u0027 allow to enter a ' in a character literal, e.g. '\''
\" \u0022 allow to enter a " in a string literal, e.g. "this is the double quote (\") character"
\\ \u005c allow to enter a \ character in a character or string literal, e.g. '\\' or "this is the backslash (\\) character"
\0 \u0000 allow to enter the character with code 0
\a \u0007 alarm (usually the HW beep)
\b \u0008 back-space
\f \u000c form-feed (next page)
\n \u000a line-feed (next line)
\r \u000d carriage-return (move to the beginning of the line)
\t \u0009 (horizontal-) tab
\v \u000b vertical-tab

关于c# - 如何在代码中写入 JSON 字符串值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13489139/

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