Json.parse无法运行 [英] Json.parse not functioning

查看:105
本文介绍了Json.parse无法运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用AJAX函数获取JSON.parse,因为TextBox5-9为空。



这应该可行。



我从WebMethod函数getDate返回两个差异实例的数据。

How do I get the JSON.parse to be evaluated in and AJAX function because TextBox5-9 are empty.

This should work.

I have returning data for both differences instances from the WebMethod function getDate.

$("#<%= TextBox4.ClientID %>").val(result.d);

打印出下面两个JSON数据中的任何一个并且正在工作。

prints out either of the two JSON data below and is working.

"[{id:1, datetime:04/10/2017, col1:1, col2:2, col3:2}]"






and

"{\"id\":1,\"datetime\":04/10/2017,\"col1\":1,\"col2\":2,\"col3\":2}]"



TextBox5-9没有提供他们应该提供的任何数据。 JSON类结构没有被读取。



这应该可行。


TextBox5-9 are not giving any data like they should. The JSON class structure is not being read.

This should work.

<script type="text/javascript" src="../Scripts/jquery-1.4.1.js"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#<%= Button1.ClientID %>").click(function () {
                var mo1 = $("#<%= TextBox1.ClientID %>").val();
                var dy1 = $("#<%= TextBox2.ClientID %>").val();
                var yr1 = $("#<%= TextBox3.ClientID %>").val();
                var data = { mo:mo1, dy:dy1, yr:yr1 };
                var json1 = JSON.stringify(data);
                
                $.ajax
                ({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    data: json1,
                    url: "Default.aspx/GetDate",
                    success: function (result) {
                        $("#<%= TextBox4.ClientID %>").val(result.d);
                        var datereturn = JSON.parse(result.d);
                        $("#<%= TextBox5.ClientID %>").val(datereturn.id);
                        $("#<%= TextBox6.ClientID %>").val(datereturn.datetime);
                        $("#<%= TextBox7.ClientID %>").val(datereturn.col1);
                        $("#<%= TextBox8.ClientID %>").val(datereturn.col2);
                        $("#<%= TextBox9.ClientID %>").val(datereturn.col3);

                    },
                    error: function (status, ex) {
                        alert("Error Code: Status: " + status + " Ex: " + ex);
                    }
                });
                return false;
            });
        });
    </script>





我尝试过:



我尝试过从WebMethod GetDate返回的许多JSON返回格式。就像我说的那样,它以正确的形式生成TextBox4中的两个JSON之一。它只是打印出Json类。我试过return而不是return.d。



What I have tried:

I have tried many returning formats of the JSON returning from the WebMethod GetDate. Like I said this produces one of the two JSONs in TextBox4 in correct form. It just does nt print out the Json Classes. I have tried "return" instead of "return.d".

推荐答案

#<%= TextBox4.ClientID%>)。val(result.d);
("#<%= TextBox4.ClientID %>").val(result.d);

打印出以下两个JSON数据中的任何一个并且是工作。

prints out either of the two JSON data below and is working.

"[{id:1, datetime:04/10/2017, col1:1, col2:2, col3:2}]"






and

"{\"id\":1,\"datetime\":04/10/2017,\"col1\":1,\"col2\":2,\"col3\":2}]"



TextBox5-9没有提供他们应该提供的任何数据。 JSON类结构没有被读取。



这应该可行。


TextBox5-9 are not giving any data like they should. The JSON class structure is not being read.

This should work.

<script type="text/javascript" src="../Scripts/jquery-1.4.1.js"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script type="text/javascript">


document )。ready( function (){
(document).ready(function () {


#<%= Button1.ClientID%>)。点击( function (){
var mo1 =
("#<%= Button1.ClientID %>").click(function () { var mo1 =


这篇关于Json.parse无法运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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