asp.net mvc - C#: Json validation from user input -
i need validate json file server side, im using asp.net mvc c#, have method in controller
public actionresult validate(httppostedfilebase jsonfile) { bool validjson = false; var serializer = new javascriptserializer(); try { var result = serializer.deserialize<dictionary<string, object>>(how should pass json file here ??); validjson = true; } catch(exception ex) { validjson = false; } }
this best way validate ? ... sorry don't know how pass json string parameter, have tried jsonfile.inputstream.tostring(), jsonfile.tostring() ... needs ?, json user's route ? ... in advance
well how this:
using (var reader = new streamreader(jsonfile.inputstream)) { string jsondata = reader.readtoend(); var serializer = new javascriptserializer(); var result = serializer.deserialize<dictionary<string, object>>(jsondata); // dragons here ... }
Comments
Post a Comment