JSON响应字符串我收到以下类型的JSON从Web服务响应:查找和替换在净
{"students":[{"studentID":"123456789","section":"S","RefId":" ","pastScore":"99952","currentScore":"99952","inquiryAllowed":true},{"studentID":"223456789","section":"R","RefId":" ,"pastScore":"152","currentScore":"952","inquiryAllowed":true},{"studentID":"323456789","section":"T","RefId":" ,"pastScore":"4582","currentScore":"5952","inquiryAllowed":true},],"schoolName":"WatsonPrimarySchool"}
我需要屏蔽studentID,pastScore,currentScore和schoolName。输出将如下所示:
{"students":[{"studentID":"$$$$$$$$","section":"S","RefId":" ","pastScore":"$$$$$","currentScore":"$$$$$","inquiryAllowed":true},{"studentID":"$$$$$$$$$","section":"R","RefId":" ,"pastScore":"$$$","currentScore":"$$$","inquiryAllowed":true},{"studentID":"$$$$$$$$$","section":"T","RefId":" ,"pastScore":"$$$$","currentScore":"$$$$","inquiryAllowed":true},],"schoolName":"$$$$$$$$$$$$$$$$$$$"}
schoolName
只会发生一次,其余的可以是多个。
我试过使用StringBuilder
,但由于值的动态性质,它没有成功。有人可以建议一个正则表达式解决方案吗?
反序列化一个对象,并在吸气这些属性返回'“$$$$$$”'或任何 – DGibbs
转到http://json2csharp.com/粘贴您的JSON格式,它会生成类。使用Json.Net将类转换为JSON,反之亦然。 – Chandru
@DGibbs - 我同意将响应转换为类并在getter中屏蔽值是一个很好的过程,但由于需要特殊要求,需要直接处理JSON字符串。 – Vguy