Updated text fields to JSON string

This question already has an answer here: Convert form data to JavaScript object with jQuery 50 answers Here is the solution, iterate through each row, find values of textbox and push it to array and finally convert it to string. you can set that string in hidden field to pass it to server side. var ArrColleague = []; $("#subdetails").click(function () { $("#mantab tr").each(function (

将文本字段更新为JSON字符串

这个问题在这里已经有了答案: 使用jQuery将表单数据转换为JavaScript对象50个答案 这里是解决方案,遍历每一行,找到文本框的值,并将其推送到数组,最后将其转换为字符串。 您可以在隐藏字段中设置该字符串以将其传递给服务器端。 var ArrColleague = []; $("#subdetails").click(function () { $("#mantab tr").each(function (index, val) { ArrColleague.push({ "c1nametb": $(val).find("#c

Dynamically build JSON object list from Javascript

This question already has an answer here: Convert form data to JavaScript object with jQuery 50 answers 创建替换属性数组并在其中推入对象: var o = {}; o.Name. = $("#Name").val(); o.Phone = $("#Phone").val(); o.Replacements = []; o.Replacements.push({ Company: $("#Company1").val(), Amount: $("#Amount1").val() }, { Company: $("#Company2").val(), Amount: $("#Amount2").val() })

从Javascript动态构建JSON对象列表

这个问题在这里已经有了答案: 使用jQuery将表单数据转换为JavaScript对象50个答案 创建替换属性数组并在其中推入对象: var o = {}; o.Name. = $("#Name").val(); o.Phone = $("#Phone").val(); o.Replacements = []; o.Replacements.push({ Company: $("#Company1").val(), Amount: $("#Amount1").val() }, { Company: $("#Company2").val(), Amount: $("#Amount2").val() }); $("#txtJSON").val(JSON.

Turn a form into an associative array in Jquery

This question already has an answer here: Convert form data to JavaScript object with jQuery 50 answers Here's a dead-simple way: $.fn.form = function() { var formData = {}; this.find('[name]').each(function() { formData[this.name] = this.value; }) return formData; }; // use like var data = $('#editForm').form(); This is totally unsafe and just grabs everythin

在Jquery中将表单转换为关联数组

这个问题在这里已经有了答案: 使用jQuery将表单数据转换为JavaScript对象50个答案 这是一个简单的方法: $.fn.form = function() { var formData = {}; this.find('[name]').each(function() { formData[this.name] = this.value; }) return formData; }; // use like var data = $('#editForm').form(); 这是完全不安全的,只是用名字抓住所有东西,但它应该让你开始。

How to get form data as a object in jquery

This question already has an answer here: Convert form data to JavaScript object with jQuery 50 answers Have you tried "serializeArray"? That gives you an array of names and values. You could turn that into an object if you wanted to: var paramObj = {}; $.each($('#myForm').serializeArray(), function(_, kv) { paramObj[kv.name] = kv.value; }); (I'll have to check again to se

如何获取表单数据作为jQuery中的对象

这个问题在这里已经有了答案: 使用jQuery将表单数据转换为JavaScript对象50个答案 你尝试过“serializeArray”吗? 这给你一个名称和值的数组。 如果你想:你可以把它变成一个对象: var paramObj = {}; $.each($('#myForm').serializeArray(), function(_, kv) { paramObj[kv.name] = kv.value; }); (我将不得不再次检查jQuery如何处理数组;我认为它将它们编码为Javascript数组值,但我不是100%确定的。) 编辑啊

Convert Object holding arrays to JSON

I have an object which contain multiple arrays like in the following screenshot: and I would like to convert it into this object: { "Manifacture": "Samsung", "Model": "Ipad 2" } in order to use the data in bootstrap table. When using stringify , I'm getting the following: "{"Manifacture":[{"id":2,"name":"Samsung"}],"Model":[{"id":1,"name":"Ipad 2"}]"}" which is different than what I n

将保存数组的对象转换为JSON

我有一个包含多个数组的对象,如下面的截图所示: 我想将它转换成这个对象: { "Manifacture": "Samsung", "Model": "Ipad 2" } 以便在引导表中使用数据。 当使用stringify ,我得到以下内容: "{"Manifacture":[{"id":2,"name":"Samsung"}],"Model":[{"id":1,"name":"Ipad 2"}]"}" 这与我所需要的不同。 可能吗? 你可以使用普通的javascript处理对象。 for (var key in obj) { obj[key] = obj[key][0].name } J

How to convert a javascript object to json

I'm trying to convert a JavaScript object to a json. Practically I have created a website where you can upload a json, edit it and download it with your changes. For convenience when I edit it creates a javascript object that will be converted at the end of the changes with JSON.stringify . The problem is that the final Json should have the same characteristics as the initial one with t

如何将JavaScript对象转换为json

我试图将JavaScript对象转换为json。 实际上,我创建了一个网站,您可以在其中上传json,对其进行编辑并将其与您的更改一起下载。 为了方便,我编辑它时会创建一个javascript对象,该对象将在JSON.stringify的更改结束时进行转换。 问题是最终的Json应该具有与最初的JSON相同的特性,并且与不同的关键元素相关联。 例如,第一个可以是这样的: "tickets": { "use": "Valida", "useagain": "Valida di nuovo",

How to simplfy the passing of parameter

I have these method in c# which requires 3 parameters public void Delete_AgentTools(int ID,int UAM,int mode) { some code etc. } and I use javascript ajax to call this method and pass the parameter function Delete_AgentTools(toolAccess, toolId, UAM) { $.ajax({ type: "POST", url: "IROA_StoredProcedures.asmx/Delete_AgentTools", data: "{'toolAccess':'" + toolAccess + "'

如何简化参数的传递

我有这些方法在C#中需要3个参数 public void Delete_AgentTools(int ID,int UAM,int mode) { some code etc. } 我使用javascript ajax来调用这个方法并传递参数 function Delete_AgentTools(toolAccess, toolId, UAM) { $.ajax({ type: "POST", url: "IROA_StoredProcedures.asmx/Delete_AgentTools", data: "{'toolAccess':'" + toolAccess + "', 'toolId':'" + toolId + "', 'UAM':'" + UAM +

converting object key value pairs to JSON

I have a javascript object with 6 key value pairs: My_Type_1:"Vegetable" My_Type_2:"Fruit" My_Type_3:"Dessert" My_Value_1: "Carrot" My_Value_2: "Apple" My_Value_3: "Cake" I want to construct JSON out of the above object such that it generates the following: [{"Vegetable":"Carrot"},{"Fruit":"Apple"},{"Dessert":"Cake"}] EDIT: for (j=0;j<3;j++) { var tvArray = new Array(); var sType

将对象键值对转换为JSON

我有一个包含6个键值对的JavaScript对象: My_Type_1:"Vegetable" My_Type_2:"Fruit" My_Type_3:"Dessert" My_Value_1: "Carrot" My_Value_2: "Apple" My_Value_3: "Cake" 我想从上述对象中构建JSON,以便它生成以下内容: [{"Vegetable":"Carrot"},{"Fruit":"Apple"},{"Dessert":"Cake"}] 编辑: for (j=0;j<3;j++) { var tvArray = new Array(); var sType = 'My_Type_'+j+1; var sValue = 'My_Value_'+j+

Json string parsing issue

var jsonString ="{ " jsonString += "name:" + Data.name+","; jsonString += "surname:"+ Data.surname+","; jsonString += "Address: " + Data.add; jsonString += "}" I am creating following json string for the Ajax call.but when there is "," in the address field. it is giving me error. can anybody tell me proper way to create json string in

Json字符串解析问题

var jsonString ="{ " jsonString += "name:" + Data.name+","; jsonString += "surname:"+ Data.surname+","; jsonString += "Address: " + Data.add; jsonString += "}" 我为Ajax调用创建了以下json字符串,但是在地址字段中存在“,”时。 它给我错误。 任何人都可以告诉我适当的方式来创建JavaScript的Ajax调用json字符串 使用JSON.stringify()来生成你的JSON字符串。

print[ [object Object],[object Object]] to json array

I want to print [object Object],[object Object] to like wise "[[{ 'x': '1', 'y': '0' }, { 'x': '2', 'y': '1' }]]"; How it is possible in javascript 如果您想要JavaScript对象的字符串表示形式,请使用JSON.stringify()

将[[object Object],[object Object]]打印到json数组

我想打印[object Object],[object Object]喜欢明智的"[[{ 'x': '1', 'y': '0' }, { 'x': '2', 'y': '1' }]]"; 如何在JavaScript中可能 如果您想要JavaScript对象的字符串表示形式,请使用JSON.stringify()