Parse JSON in Knockout into Dictionary Key Value in C#

杀马特。学长 韩版系。学妹 提交于 2019-12-25 03:00:16

问题


I have following knockout text binding :

 <td><strong><span id="texthotelcode" data-bind="text: parameters"
 /></strong></td>

data binding of text: which returns data: {"id1":"2Z94","id2":"9861"}

now I want to convert them from this JSON into Key and value in Dictionary in C# as string, string

Any idea for this case thanks


回答1:


.net can deserialize JSON in the following form into c# dictionary:

dict: [ 
         { "Key": "id1", "Value": "2Z94" },
         { "Key": "id2", "Value": "9861" }
      ]

So you can use a function like this one to convert your object:

function toDictionary(data) {
    var dict = [];
    for (var prop in data)
        dict.push({ "Key": prop, "Value": data[prop] });
    return dict;
}

Then just send this object to the server.


Note that as andyp pointed out, there is a similar question with answers in this thread.

When in search for an answer, please search the site first, and post your question only when no answer fits your needs. In this case, the other thread might need some update.



来源:https://stackoverflow.com/questions/23873562/parse-json-in-knockout-into-dictionary-key-value-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!