After JSON serialization, the page shows a problem with a backslash ' \ ' __js

Source: Internet
Author: User
Tags serialization

In the project, the foreground data is the JSON string, because there is no suitable entity to these fields, all in the simplest way: intercept the string.


The foreground JSON string is:


string S1 = "[{\ id\": \ "99d2a341-ea2e-4f04-b4f4-623153d64336\", \ "name\": \ "Harry \", \ "totalscores\": 80,\ "productivity \": \ "B\", \ "Professional ethics": \ "B\", "business capability": \ "a\", "link self-discipline": "B\", "Work performance \": \ "b\"},{\ "id\": \ "728f72ac-473b-4bde-bf83-7ed93d3fd9e6\", \ "name\": \ "Dick \", \ "totalscores\": 80,\ "work efficiency \": \ "B\", "Professional Ethics": \ "B\", "Business capability \": \ "a\", "link self-discipline \": \ "B\", "Performance \": \ "B\"} , {\ "id\": \ "29c80443-d0ac-414c-91b5-acd5e69e28f2\", "name\": \ "Liu Qi", "totalscores\": 80,\ "work efficiency": \ "B\", "Professional ethics": \ "B\", \ "business capability \": \ "a\", "link self-discipline": \ "B\", "Work performance \": \ "B\"}] ";

You can see in fact in Microsoft in the "\" as double quotes, the idea is this:


1, remove "\" "


Code implementation:


Strings11=s1. Replace ("\", "");

2, remove "[]"


Code implementation:


String S22 =s11. Replace ("[", "");

String S33 =s22. Replace ("]", "");

This is the time we get the S33 is this:


S33= "{id:99d2a341-ea2e-4f04-b4f4-623153d64336,name: Harry, totalscores:80, work efficiency: B, Professional ethics: B, Business ability: A, link self-discipline: B, work score: B},{id : 728f72ac-473b-4bde-bf83-7ed93d3fd9e6,name: Dick, totalscores:80, work efficiency: B, Professional ethics: B, Business ability: A, link self-discipline: B, work score: B},{id : 29c80443-d0ac-414c-91b5-acd5e69e28f2,name: Liu Qi, totalscores:80, work efficiency: B, Professional ethics: B, Business ability: A, link self-discipline: B, performance: B} "

3, replace "},{" to "}", remove null value


Code implementation:


String S44 =s33. Replace ("},{", "}");


S44= "{id:99d2a341-ea2e-4f04-b4f4-623153d64336,name: Harry, totalscores:80, work efficiency: B, Professional ethics: B, Business ability: A, link self-discipline: B, work score: B}id : 728f72ac-473b-4bde-bf83-7ed93d3fd9e6,name: Dick, totalscores:80, work efficiency: B, Professional ethics: B, Business ability: A, link self-discipline: B, work score: B}id : 29c80443-d0ac-414c-91b5-acd5e69e28f2,name: Liu Qi, totalscores:80, work efficiency: B, Professional ethics: B, Business ability: A, link self-discipline: B, performance: B} "

String[] s55s =s44. Split (new char[] {'} ', ' {'}, stringsplitoptions.removeemptyentries);


S55s is the "Id:99d2a341-ea2e-4f04-b4f4-623153d64336,name: Harry, ..." to put the resulting results in the dictionary:


<span style= "FONT-SIZE:18PX;" > for (int i = 0; i < updatededit.length i++) {//string[] Detailevaluationinfo = updatededit[ I].
                    Split (', ');
                    String Pat = @ "(? <key>[^,:\s]*):(<value>[^,:\s]*)"; A group of data is taken out//for (int j = 0; J < Detailevaluationinfo. Length;
                        J + +) {MatchCollection matches = regex.matches (Updatededit[i], Pat);
                        dictionary<string, string> dict = new dictionary<string, string> (); foreach (Match m in matches) {if dict. ContainsKey (m.groups["key"). Value) continue;//can not repeat Ah Dict. ADD (m.groups["key"). Value, m.groups["value"].
                        Value); }}</span>


This allows you to intercept the JSON string.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.