简体   繁体   中英

Assigning json string to a variable in C#

I have the JSON string that I want to use in my C# program.

var responseBytes = "{ "class":"TPV","device":"tcp://172.19.34.3:50000","mode":3,"time":"2017-09-20T02:55:15.000Z","ept":0.005,"lat":-36.853230000,"lon":174.773626667,"alt":40.200,"epv":23.000,"track":246.3700,"speed":0.000,"climb":0.000,"epc":46.00}";

But my VisualStudio Editor is showing errors for the above decleration. It is probably because of the lack of escape characters. How do I fix this?

can not use " inside "" directly

to solve this use \\" all quotations inside Double quotations

or use ' except " inside double Quotation

var responseBytes = "{ \"class\":\"TPV\",\"device\":\"tcp:172.19.34.3:50000\",\"mode\":3,\"time\":\"2017-09-20T02:55:15.000Z\",\"ept\":0.005,\"lat\":-36.853230000,\"lon\":174.773626667,\"alt\":40.200,\"epv\":23.000,\"track\":246.3700,\"speed\":0.000,\"climb\":0.000,\"epc\":46.00}";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM