How to write JSON format characters into the text file

Source: Internet
Author: User

This article is a step-by-step study of how to write the JSON-formatted strings displayed in the Web page into the text file and save them.
Learn to create model, Entity, serialized list<object> converted to JSON, displayed on the Web page. Then it is the way to transfer these JSON strings to the controller, write the text file and save it.

To prepare the data object, create the model:

Next, create entity, data entities, data can be from files, databases or other. The following data is insus.net written as static. So the example above is just a demonstration.

ASP. NET MVC program development, controller is very not. We created a controller, it's March 2015 now, and the time is going really fast, we're going to MarchY15:

In the views directory you will see a MarchY15 directory, the high version of ASP. NET MVC after the creation of a good controller, the views directory will automatically create a corresponding directory.
Just now in the controller, we have created the good one view operation Writejsonstringtotext, we create a view with this name:

Mark 1, create the view.

Tag 2, place an ammonium button in the Web page to get the JSON-formatted string.

Marker 3, displaying the JSON string position.

Tag 4, pass the JSON text to the controller, write it into the text file, and save it.

Tag 5, referencing the jquery class library.

Mark 6, write a jquery program.

Now we have to deal with the Entity data displayed on the Web page, you need to write a method on the controller:

There's one on the top. ToJson () extension method, you can refer to the previous ASP. NET MVC Learning example, which is the extension method of converting list<t> to JSON. No longer described here.

Now that you have a demo of getting the data and displaying it, the runtime finds an error:

After checking, it was found that the controller suffix was removed when the controllers were created.

Fill it up and run it again:

Next, we need to put the JSON-formatted files displayed in the Web page into the text file and save them.
Re-open the control MarchY15 controller and add an action:


Go back to the view and continue writing the Button2 Click event:

OK, here's a demo:

How to write JSON format characters into the text file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.