English 中文(简体)
to子管区
原标题:Issue parsing arrays to json

My problem: I m writing a web app to manage contacts. On the server side, i m working with Razor Syntax (C#) and i m sending ajax requests to my server with a json encoded string as header. The test.cshtml recieves this as follows:

var j = Json.Decode(Request["json"]);

现在,我可以完全使用所有物体。 BUT! 我在 j子里有一阵列,像......,“人”:[1,2,3],<....../code>。 The Json. 编码的编码是这样,因为它应当放在一个可以用来向我的数据库书写数据的阵列上。 在这样做之后,我要向客户发送更新的物体(阵列没有改变,也没有做任何其它事情),使用:

<text>
    @Html.Raw(Json.Encode(j));
    @j.persons.Length;
</text>

人事部分的输出为......,“人”:{},......,但人员长度为3人。 我做了什么错误? 是否有计算Json的参数。 • 编码以编码分目标和阵列?

感谢你的支持

PS:@j.persons. 长度只是证明阵列不是空的,是现有的。

最佳回答

我发现这个问题。 我不得不将自动生成的阵列(从Json.Decode)与 lo合起来:

int[] temp = new int[j.persons.Length];
for(var i = 0;i < j.persons.Length;i++){
    temp[i] = (j.persons[i] is string)?Int32.Parse(j.persons[i]):(int)j.persons[i];
}
j.persons = temp;

感谢你的做法

问题回答

因为它只保护了根基,而不是人尝试j.as_json(include => :persons)





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...