Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 18:02:20
Original
988 people have browsed it

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.
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template