c# - Trim JSON fields, not working for nested JSON -
i want trim string field in json. use own jsonconverter (code below, newtonsoft), added on mvc application start in global.asax. go fine, if there no nested json. if there is, nested json not handled. why? should change fix it?
for example
{"name":" jacek ","age" = " 10 "} working {"name":" jacek ","age"=" 10 "."address":{"street":" long "}} not working street, works name , age.
my string converter string
public class mystringconverter : jsonconverter { public override bool canconvert(type objecttype) { return objecttype == typeof(string); } public override bool canread { { return true; } } public override object readjson(jsonreader reader, type objecttype, object existingvalue, jsonserializer serializer) { var text = (string)reader.value; return triminputfield(text); } public override void writejson(jsonwriter writer, object value, jsonserializer serializer) { writer.writevalue(value); } public string triminputfield(string input) { if (false == string.isnullorempty(input)) { input = input.trim(); var regex = new regex(@"\s+"); input = regex.replace(input, " "); } return input; } }
Comments
Post a Comment