locked
JSON Serialization Problem RRS feed

  • Question

  • User-2059141420 posted

    Hi all,

    I want to serialize an object to JSON. Is there a smart way to do this?

    My array as

    var people= new Array();
    people[0] = 'mad';
    people[1] = 'normal';
    ...

    Can anyone please help me? Thanks

    Saturday, January 12, 2019 9:58 AM

Answers

  • User-552477072 posted

    Hi Robert,

    You can use stringify in your Ajax call as

    $.ajax({
    url: post_http_site,
    type: "POST",
    data: JSON.parse(JSON.stringify(Json_PostData)),
    cache: false,
    error: function (xhr, ajaxOptions, thrownError) {
    alert(" write json item, Ajax error! " + xhr.status + " error =" + thrownError + " xhr.responseText = " + xhr.responseText );
    },
    success: function (data) {
    alert("write json item, Ajax OK");

    }
    });

    Please don't forget to mark as answer if it helps you. Thanks!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, January 12, 2019 10:03 AM