Javascript asp.net中的JSON列表

Javascript asp.net中的JSON列表,javascript,asp.net,Javascript,Asp.net,我从服务器接收到错误的JSON,这是一个实际数组的字符串,所以我使用的是JSON.parse。我查看了asp代码,发现开发人员正在将列表转换为JSON。将列表编码为JSON格式的最佳方法是什么 我得到的数据: {d:“[\\”[597059715972597359765974597559775978],[343232]\\“]”} 数据应如下所示: {d:[[597059715972597359765974597559775978],[343232]] 这是一点点JSON,但它是5MB的JSON

我从服务器接收到错误的JSON,这是一个实际数组的字符串,所以我使用的是JSON.parse。我查看了asp代码,发现开发人员正在将列表转换为JSON。将列表编码为JSON格式的最佳方法是什么

我得到的数据: {d:“[\\”[597059715972597359765974597559775978],[343232]\\“]”}

数据应如下所示: {d:[[597059715972597359765974597559775978],[343232]]

这是一点点JSON,但它是5MB的JSON,因此解析需要很多时间

我真的很感激如果有人能帮我找到解决这个问题的办法,因为我是一个用户界面的家伙。

asp代码是实际调用c sharp函数的代码:

public static string GetLevelChildsList(string strInputString)
    {
        List<IndexReleationship> inflationRelationship = SessionManager.InflationRelation;
        string[] inputArguments = strInputString.Split('~');
        int intInflationModelLevelID = int.Parse(inputArguments[0].Trim());
        List<string> lstResultString = new List<string>();
        List<List<int>> strList = new List<List<int>>();
        List<int> strInflationHideIdList = new List<int>();
        List<int> strInflationShowIdList = new List<int>();
        List<int> strActualLevelids = new List<int>();
        List<int> selectedLevelids = new List<int>();
        for (int count = 0; count < inflationRelationship.Count; count++)
        {
            if (inflationRelationship[count].IsReleatedIndex > intInflationModelLevelID)
            {
                if (!strInflationHideIdList.Contains(inflationRelationship[count].ParentIndexID))
                {
                    strInflationHideIdList.Add(inflationRelationship[count].ParentIndexID);
                }

                if (!strInflationHideIdList.Contains(inflationRelationship[count].ChildIndexID))
                {
                    strInflationHideIdList.Add(inflationRelationship[count].ChildIndexID);
                }

            }
            else if (inflationRelationship[count].IsReleatedIndex == intInflationModelLevelID
                     && inflationRelationship[count].IsReleatedIndex != 1169)
            {
                if (!strActualLevelids.Contains(inflationRelationship[count].ChildIndexID))
                {
                    strActualLevelids.Add(inflationRelationship[count].ChildIndexID);
                }
            }
            else
            {
                if (!strInflationShowIdList.Contains(inflationRelationship[count].ParentIndexID))
                {
                    strInflationShowIdList.Add(inflationRelationship[count].ParentIndexID);
                }

                if (!strInflationShowIdList.Contains(inflationRelationship[count].ChildIndexID))
                {
                    strInflationShowIdList.Add(inflationRelationship[count].ChildIndexID);
                }
            }

        }

        strList.Add(strInflationHideIdList);
        strList.Add(strInflationShowIdList);
        strList.Add(strActualLevelids);

        selectedLevelids.AddRange(strInflationShowIdList);
        selectedLevelids.AddRange(strActualLevelids);

        string strResult = GetSessionInflationModels(selectedLevelids);
        lstResultString.Add(strList.ToJson());
        lstResultString.Add(strResult);
        return lstResultString.ToJson();
    }
public静态字符串GetLevelChildsList(字符串strInputString)
{
List inflationRelationship=SessionManager.inflationRelationship;
string[]inputArguments=strInputString.Split('~');
int intInflationModelLevelID=int.Parse(inputArguments[0].Trim());
List LSTRUSTSTRING=新列表();
List strList=新列表();
List strInflationHideIdList=新列表();
List strInflationShowIdList=new List();
List strActualLevelids=新列表();
List selectedLevelids=新建列表();
对于(int count=0;countIntinflationModelLevel ID)
{
如果(!StrinFlationHideList.Contains(通货膨胀关系[count].ParentIndexID))
{
StrinFlationHideList.Add(通货膨胀关系[count].ParentIndexID);
}
如果(!StrinFlationHideList.Contains(通货膨胀关系[count].ChildIndexID))
{
StrinFlationHideList.Add(通货膨胀关系[count].ChildIndexID);
}
}
else if(通货膨胀关系[count].IsRelatedIndex==IntinFlationModelLevel ID
&&通货膨胀关系[count].IsRelatedIndex!=1169)
{
如果(!StractualLevel.Contains(通货膨胀关系[count].ChildIndexID))
{
StractualLevel.Add(通货膨胀关系[count].ChildIndexID);
}
}
其他的
{
如果(!strInflationShowIdList.Contains(通货膨胀关系[count].ParentIndexID))
{
StrinfRelationsHowidList.Add(通货膨胀关系[count].ParentIndexID);
}
如果(!strInflationShowIdList.Contains(通货膨胀关系[count].ChildIndexID))
{
strInflationShowIdList.Add(通货膨胀关系[count].ChildIndexID);
}
}
}
添加(StrinFlationHideList);
添加(strInflationShowIdList);
strList.Add(strActualLevelids);
selectedLevelids.AddRange(StrinRelationsShowIdList);
selectedLevelids.AddRange(strActualLevelids);
字符串strResult=GetSessionInflationModels(SelectedLevelId);
lstreultString.Add(strList.ToJson());
lstResultString.Add(strResult);
返回lstrestString.ToJson();
}

我建议使用JSON.NET库将列表序列化为JSON,而不是尝试自己创建JSON。这几乎是目前.NET中处理JSON的标准方式:

然后可以创建这样的对象(我将忽略一些常见的.NET约定,以保持此示例的简单性,例如大写)


字符串将是您尝试返回的有效JSON。

您可以转到此链接查看问题:您是否正在尝试修复返回错误JSON的ASP.NET服务,或者找出如何在javascript中使用错误的JSON?我正在尝试修复asp代码,以便它返回健康的JSON,而js不必进行额外的计算。您可以发布当前用于生成JSON字符串的C#或VB.NET代码吗?如果我们能看到当前代码的错误所在,我们可能会更快地得到答案。我将感谢任何形式的输入。谢谢你。我会把这个链接给我的开发团队,希望他们能够实现它。如果他们有任何问题,请告诉我。我已经使用(现在仍然使用)JSON.NET库好几年了。
public class MyObject
{
    public List<List<int>> d { get; set; }
}
MyObject myObj = new MyObject();
myObj.d = strList;
string output = JsonConvert.SerializeObject(myObj);