代码中书写Json字串格式

版权声明:所有版权归作者她的吻让他,转载请标明出处. https://blog.csdn.net/qq_37059136/article/details/82893716

说出来有点尴尬,虽然知道Json的书写格式,但是实际在代码中敲一串Json字串却会因为添加转义字符而搞得有点头晕,这里特意给出文章以帮助跟我一样解决初次接触Json字串时头晕的尴尬局面

其实这种局面我们要的不过是一个模板,下面给出cJson官网测试时使用的Json字串

char text1[]="{\n\"name\": \"Jack (\\\"Bee\\\") Nimble\", \n\"format\": {\"type\":       \"rect\", \n\"width\":      1920, \n\"height\":     1080, \n\"interlace\":  false,\"frame rate\": 24\n}\n}";	
	char text2[]="[\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"]";
	char text3[]="[\n    [0, -1, 0],\n    [1, 0, 0],\n    [0, 0, 1]\n	]\n";
	char text4[]="{\n		\"Image\": {\n			\"Width\":  800,\n			\"Height\": 600,\n			\"Title\":  \"View from 15th Floor\",\n			\"Thumbnail\": {\n				\"Url\":    \"http:/*www.example.com/image/481989943\",\n				\"Height\": 125,\n				\"Width\":  \"100\"\n			},\n			\"IDs\": [116, 943, 234, 38793]\n		}\n	}";
	char text5[]="[\n	 {\n	 \"precision\": \"zip\",\n	 \"Latitude\":  37.7668,\n	 \"Longitude\": -122.3959,\n	 \"Address\":   \"\",\n	 \"City\":      \"SAN FRANCISCO\",\n	 \"State\":     \"CA\",\n	 \"Zip\":       \"94107\",\n	 \"Country\":   \"US\"\n	 },\n	 {\n	 \"precision\": \"zip\",\n	 \"Latitude\":  37.371991,\n	 \"Longitude\": -122.026020,\n	 \"Address\":   \"\",\n	 \"City\":      \"SUNNYVALE\",\n	 \"State\":     \"CA\",\n	 \"Zip\":       \"94085\",\n	 \"Country\":   \"US\"\n	 }\n	 ]";

可以先看cJson官网测试时使用的Json字串,如果不甚明白我这里给一个简单的Json字串

string strRequest="{\"configInfos\":\"00\",\"ServiceReqMsg\":\"encrptyNewServiceReqMsg\"}";

c语言定义" "里面定义字符串,如果在" "里面出现特殊字符就需要使用转义字符\

猜你喜欢

转载自blog.csdn.net/qq_37059136/article/details/82893716
今日推荐