当前位置: 动力学知识库 > 问答 > 编程问答 >

Accessing nameless attributes from JSON in VB .Net using DataContract

问题描述:

I'm trying to serialize in VB .Net a JSON file that contains this:

"scripts": [[123, 80, [["whenKeyPressed", "space"], ["nextCostume"]]],

[55, 32, [["whenKeyPressed", "space"], ["doPlaySoundAndWait", "Hello"]]]]

I'm using DataContract and <DataMember(Name:="scripts")> and it works fine for the rest of the file, but in this case, the attributes don't have names. JSONlint.com, the JSON Validator, is saying this is valid JSON.

How am I suppose the qualify the DataMembers? Also, it has a nameless array in it, how can I can I access it?

Any help would be appreciated.

网友答案:

I finally found a workaround by assigning scripts to a List(Of Object) in the DataContract, then casting scripts to the desired type at runtime. I casted it as IList(Of Object) for the lists and then iterated in them for For loops.

It doesn't "feel" as "object-oriented" as the rest and I can't reference the fields by name (since they have none), but it works (with a lot of casting, especially since I work with Option Strict On).

If there is a better way, I am open to suggestions.

分享给朋友:
您可能感兴趣的文章:
随机阅读: