English 中文(简体)
Parse Json Object
原标题:Parse Json Object

我有一个名单错误实体,我用来将错误和错误的信息传递给德国马克。

   public class ErrorEntity
    {
       public int ErrorId
       {
           get;
           set;
       }

       public string ErrorMessage
       {
           get;
           set;
       }
    }
}

我将这个物体寄给正在编印的Javascript。

Json 我在经历过序列化之后,像以往一样。

[{"ErrorId":1,"ErrorMessage":"Test has not been prepared for tag EP105"},{"ErrorId":2,"ErrorMessage":"Test has not been prepared for tag EP105"}]

现在,我需要把这名Json语拼凑起来,向用户展示错误信息。 让我知道,我怎么说。 我是否需要写一字,以便顺从。

http://www.ohchr.org。 在我的主页上,我正试图加以平息。

function ShowErrorMsg(jsonObject) {  
  for (i = 0; i < jsonObject.Object.length; i++) { //Object is undefined here.
    alert(jsonObject.Object.ErrorMessage);
  }          
}
最佳回答

Prefer JSONparse()

var jsonArray = JSON.parse(serializedString);
window.alert(jsonArray[0].ErrorMessage);

Fall re to eval(否则:

var jsonArray = eval(serializedString);
window.alert(jsonArray[0].ErrorMessage);
问题回答

Try Json.NET

There is support in most browsers for parsing json, I recommend to use jQuery for this - you also can take a look at this

了解——更好地使用图书馆,而不是为此利用联合材料(JS是来自诽谤;)





相关问题
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. ...

热门标签