Is there a better way to convert a JSON packet into a query string?

前端 未结 1 1480
[愿得一人]
[愿得一人] 2020-12-21 23:28

I have an input string that will either be a JSON packet, ala:

{\"PHONE\":\"555-513-4318\",\"FIRSTNAME\":\"Austin\",\"ARTISTID\":\"2\",\"LASTNAME\":         


        
相关标签:
1条回答
  • 2020-12-22 00:00

    There's not a much shorter way to do this, other than optimizing it just a little:

    var data = $("#content").val();
    try {
      data = $.param($.parseJSON(data));
    } catch (e) { }
    

    This prevents the potential multiple selector and .val() calls, but the same concept as you're already doing.

    0 讨论(0)
提交回复
热议问题