如何使用POST方法重新创建JSON文件 [英] How do I recreate a JSON file using the POST method

查看:81
本文介绍了如何使用POST方法重新创建JSON文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为〜/ data.txt的json文件,该文件来自Default.aspx.cs中的Serializer,它放在Hidden1文本框中。



尝试在json.aspx页面重新创建它。



Default.aspx

I have a json file called "~/data.txt" resulting from a "Serializer" in Default.aspx.cs which is placed into the Hidden1 textbox.

Trying to recreate it in json.aspx page.

Default.aspx

<form action="json.aspx" method="post">
    <input id="Hidden1" type="hidden" runat="server" />
</form>



json.aspx


json.aspx

<script type="text/javascript">
    $.ajax(
         {
             url: "~/Default.aspx",
             contentType: 'application/json',
             data: JSON.stringify("Hidden1.Value"),
             dataType: "json",
             type: "POST"
         }).done(function (result) { });

</script>

推荐答案

.ajax(
{
url: 〜/ Default.aspx
contentType:' < span class =code-string> application / json',
data: JSON .stringify( Hidden1.Value),
dataType: json
type: POST
})。done( function (result){});

< / script>
.ajax( { url: "~/Default.aspx", contentType: 'application/json', data: JSON.stringify("Hidden1.Value"), dataType: "json", type: "POST" }).done(function (result) { }); </script>


假设你在Javascript中序列化,需要在.NET中反序列化。请看我过去的答案:

如何将对象类型转换为C#类对象类型 [ ^ ],

如何将多级json数据转换为C#对象? [ ^ ]。



如果你在.NET中都这样做,那么解决方案就是使用 DataContractJSONSerializer 。请参阅我过去的回答:

对json字符串进行解除分类数组 [ ^ ]。



参见: 使用数据合同 [ ^ ]。



-SA
Suppose you serialize in Javascript, need to deserialize in .NET. Please see my past answers:
How To Convert object type to C# class object type[^],
how to conver multi level json data to C# Object?[^].

If you do both in .NET, the solution is just using DataContractJSONSerializer. Please see my past answer:
deseralize a json string array[^].

See also: Using Data Contracts[^].

—SA


这篇关于如何使用POST方法重新创建JSON文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆