Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在visual Basic中循环客户端对象数组?_C#_Asp.net_Vb.net_Json_Object - Fatal编程技术网

C# 如何在visual Basic中循环客户端对象数组?

C# 如何在visual Basic中循环客户端对象数组?,c#,asp.net,vb.net,json,object,C#,Asp.net,Vb.net,Json,Object,我在客户端创建了一个JSON对象,然后将其传递到asp:HiddenField 这是对象的一部分 "[{"value":"0","column":"lngTask"},{"value":"End Checklist","column":"strTask"}, {"value":"0","column":"lngChecklistRevision"}, {"value":"","column":"lngManagedTask"}......]" 然后我想在我正在使用的visualbasi

我在客户端创建了一个JSON对象,然后将其传递到
asp:HiddenField

这是
对象的一部分

"[{"value":"0","column":"lngTask"},{"value":"End Checklist","column":"strTask"},
  {"value":"0","column":"lngChecklistRevision"},
  {"value":"","column":"lngManagedTask"}......]"
然后我想在我正在使用的
visualbasic

所以我使用了
JavaScriptSerializer()
如下:

Dim jss As New JavaScriptSerializer()
Dim lstReport As List(Of Object) = jss.Deserialize(Of List(Of Object))
    (hfObjSqlGridRow.Value)
以下是我的
lstReport
的外观:

我的问题是如何循环通过这个对象

我尝试过以下方法:

lsReport(0)(0)
lsReport(0).(0).value
lsReport(0).value
没有任何效果我得到这个错误=给定的键在字典中不存在。这段代码是用C#编写的,但是应该很容易转换成VB.NET。基本前提是使用动态JSON序列化程序,它允许在运行时访问属性,就像JavaScript中的JSON对象一样。您必须使用.NET 4.0来支持动态对象


您能不能对每个循环使用

lsReport中每个项目的

'使用item.value执行任何需要的操作
下一个
试试这个:

dim JSObject as String =
[
  {"00ID": "PTDA_000ParentCat_000Cat_000SubCat_000_ParentCatTxt", "00Val": "Page"}, 
  {"00ID": "PTDA_000ParentCat_000Cat_000SubCat_001_CatTxt", "00Val": "Inherite Parent"}, 
  {"00ID": "PTDA_000ParentCat_000Cat_000SubCat_002_SubCatTxt", "00Val": "Inherite Parent"}, 
  {"00ID": "PTDA_000ParentCat_000Cat_000SubCat_010_UCI", "00UCItype" : "UCItf", "00Val": "false", "01Txt": "Include related containers", "02Tip": "include related containers"}
]

            Dim serializer As JavaScriptSerializer = New JavaScriptSerializer()
            Dim obj As Object = serializer.Deserialize(Of Object)(JSObject)

    s = GetProp(obj, "PTDA_000ParentCat_000Cat_000SubCat_000_ParentCatTxt.00Val")
            SetProp(obj, "PTDA_000ParentCat_000Cat_000SubCat_000_ParentCatTxt.00Val", "NEwVal")
            s = GetProp(obj, "PTDA_000ParentCat_000Cat_000SubCat_000_ParentCatTxt.00Val")
            s = ""

Public Function GetProp(objf As Object, propPath As String) As String
    Dim propVal As String = ""
    Dim propPathAr As Array = Split(propPath, ".")
    'http://stackoverflow.com/questions/8118019/vb-net-json-deserialize
    For Each item In objf
        If item("00ID") = propPathAr(0) Then
            propVal = item(propPathAr(1))
            Exit For
        End If
    Next
    Return propVal
End Function
Public Sub SetProp(ByRef objf As Object, propPath As String, val As String)
    Dim propPathAr As Array = Split(propPath, ".")
    For Each item In objf
        If item("00ID") = propPathAr(0) Then
            item(propPathAr(1)) = val
            Exit Sub
        End If
    Next
End Sub

同样的应该适用于VB设置选项严格关闭。请添加一些解释和编辑代码,这完全是一团糟。