如何写代码JSON字符串值? [英] How to write JSON string value in code?

查看:203
本文介绍了如何写代码JSON字符串值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要存储在一个字符串变量

I want to store the following string in a String variable

{ID:123,DateOfRegistration: 2012-10-21T00:00:00 + 05:30,状态:0}

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

这是我使用的代码..

This is the code I use ..

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



..但它显示的错误。

.. but it's showing error ..

推荐答案

您必须这样做

You have to do this

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




请的看到这个参考
同样的


Please see this for reference
Also 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

这篇关于如何写代码JSON字符串值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆