请有人帮我从这个JSON中获取每个分支中的branch_id吗?
{
"branches": {
"1": {
"member_id": "-16",
"branch_id": "1"
},
"2": {
"member_id": "-16",
"branch_id": "1"
}
}
}
我正在使用JavaScriptSerialiser来反序列化JSON,但我没有正确地执行它,因为我认为JSON不是像以前一样使用过的数组:
Dim jss As New JavaScriptSerializer()
Dim data As OfficeCheckJsonResponse = jss.Deserialize(Of OfficeCheckJsonResponse)(responseFromServer)
答案 0 :(得分:1)
使用Newtonsoft,对象类型是字典(整数,SampleClass),就像在同一主题中一样,检查链接 Go This Link
Dim JsonSettings = New Newtonsoft.Json.JsonSerializerSettings
JsonSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore
Dim OutObject = Newtonsoft.Json.JsonConvert.DeserializeObject(Of branch)("###JSONSTRING###")
Public Class branch
Property branches As Dictionary(Of Integer, SampleClass)
Class SampleClass
Property member_id As String
Property branch_id As String
End Class
End Class
Class在Value属性中,Key是Unique String,如本例1,2,3,4 ......
For Each DictionaryElement As KeyValuePair(Of String, BranchesData) In branches
Debug.Print(DictionaryElement.Key) 'Is Key 1,2,3 etc..
'DictionaryElement.Value is BranchesData
Debug.Print(DictionaryElement.Value.branch_id)
Debug.Print(DictionaryElement.Value.member_id)
Next
答案 1 :(得分:1)
声明@foreach($dataProductquantity as $Productquantity)
<div class="col-lg-4 col-md-6 mb-4">
<div class="card h-100">
<a href="#"><img class="card-img-top" src="{{ asset('productimg') }}/{{$Productquantity->pic}}" alt=""></a>
<div class="card-body">
<h4 class="card-title">
<a href="#">{{$Productquantity->product->product_name}}</a>
</h4>
<h5>₱ {{$Productquantity->price}}.00 </h5>
<p class="card-text">{{$Productquantity->description}}</p>
</div>
<div class="card-footer" align="center">
<a class="btn btn-warning" align="center"><i class="icon-shopping-cart"></i><span style="color:#fff;">Add to Cart</span></a>
</div>
</div>
</div>
@endforeach
课程并向Branch
课程添加属性branches As Dictionary(Of String, Branch)
。
使用JavaScriptSerialiser,将JSON反序列化为OfficeCheckJsonResponse
的实例。
您可以通过迭代OfficeCheckJsonResponse
来获取branch_id
值。您也可以使用LINQ。
data.branches