c# - to_json (rails ) similar function for ASP.NET MVC / .NET -
In the rail, you can do the following to convert an object to Jason, but only the objects in the subsets of the fields included with.
@ user.to_json: only => However, I am currently using the ASP.NET MVC JSN function, it does not define which field I want to include in the conversion. So my question is whether JSON.NET has a function or not, and it will accept Jason before specific areas of conversion. Edit: Your answer should also include array scenarios.
@ users.to_json: only => [: Name, phone]
You can use anonymous forms: < / P>
Public Efficiency Some Actionaters (Jason) {var SomeObjectThatContainsManyProperties = GetObjectFromSomeWhere (); Returns Jason (new {name = some objectattent relations multiple properties. Name, phone = some objectsattagentimesManiprophytepes.phon,}); }
will return {"name": "John", "phone": "123"}
update :
The same technique can be used for array scenarios:
public actions Some results are from someActionThatReturnsJson () {var user = GetObjects elements (where ) Select new {name = element name, phone = element phone,}; Returns Jason (User. Toure ()); }
Comments
Post a Comment