Home  >  Article  >  Web Front-end  >  Using Json is more friendly and more object-oriented than using string to return data_json

Using Json is more friendly and more object-oriented than using string to return data_json

WBOY
WBOYOriginal
2016-05-16 18:02:20942browse

Previous program:

Copy code The code is as follows:

ViewData["msg"] = " {result:true,FileName:"" new FileInfo(Request.Files[0].FileName).Name
"",FileUrl:"" fileurl.Replace(""", "") ""}";

The program after reconstruction:
Copy the code The code is as follows:

JsonResult j = Json(new
{
Result = true,
FileName = new FileInfo(Request.Files[0].FileName).Name,
FileUrl = fileurl.Replace("" ", "")
});
ViewData["msg"] = j.Data.ToString();

Obviously, the second way is more readable , the first one is slightly better than the second one in terms of performance, but for programs, performance is only one aspect

In terms of object-oriented programs, its possibility, writing code is not prone to errors, and the rate is also very high Important, therefore, it is recommended to use the Json provided by C# when returning complex string characters, instead of spelling the Json format returned by JS yourself.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn