Make ASP.NET WCF convert dictionary to JSON, omitting “Key” & “Value” tags

后端 未结 5 1675
别跟我提以往
别跟我提以往 2020-11-27 05:58

Here\'s my dilemma. I\'m using a RESTful ASP.NET service, trying to get a function to return a JSON string in this format:

{\"Test1Key\":\"Test1Value\",\"Te         


        
5条回答
  •  广开言路
    2020-11-27 06:38

    In case anyone has that problem on the client side: conversion from that weird {Key: "x", Value:"y"} Array to a { x: "y" } object can be done in a single line of JS:

    var o = i.reduce(function (p, c, a, i) { p[c.Key] = c.Value; return p }, {});
    

    with i being the array returned from the service, and o being what you actually want.

    best regards

提交回复
热议问题