2014-01-30 3 views
0

리소스 통계를 검색하기 위해 http로 http를 호출하는 작은 응용 프로그램이 있습니다.json 객체를 반복 할 때 예기치 않은 결과가 발생했습니다.

0 메모리 사용 1 개 CPU 사용 3 차 저장 영역 5 개 관리 IP를 6 차 :있는 자원의 6 종류가 있으며, 기본적으로

{ "listcapacityresponse" : { "count":6 ,"capacity" : [ {"type":6,"zoneid":"f26c2094-f2ca-4951-9265-a3f036e7f045","zonename":" CloudPlatform 1","capacityused":45660766208,"capacitytotal":106308304896,"percentused":"42.95"}, {"type":8,"zoneid":"f26c2094-f2ca-4951-9265-a3f036e7f045","zonename":" CloudPlatform 1","capacityused":5,"capacitytotal":18,"percentused":"27.78"}, {"type":5,"zoneid":"f26c2094-f2ca-4951-9265-a3f036e7f045","zonename":" CloudPlatform 1","capacityused":3,"capacitytotal":12,"percentused":"25"}, {"type":3,"zoneid":"f26c2094-f2ca-4951-9265-a3f036e7f045","zonename":" CloudPlatform 1","capacityused":90202701824,"capacitytotal":1099511627776,"percentused":"8.2"}, {"type":1,"zoneid":"f26c2094-f2ca-4951-9265-a3f036e7f045","zonename":" CloudPlatform 1","capacityused":1500,"capacitytotal":52800,"percentused":"2.84"}, {"type":0,"zoneid":"f26c2094-f2ca-4951-9265-a3f036e7f045","zonename":" CloudPlatform 1","capacityused":1476395008,"capacitytotal":97078222080,"percentused":"1.52"} ] } } 

: 나는이 비슷한 JSON 응답을 얻을 저장 8 공유 네트워크 IP를

나는이 같은 JSON을 구문 분석하고 있습니다 :

Dim dtoObj = Newtonsoft.Json.JsonConvert.DeserializeObject(Of RootObject)(resourceusageresponse) 
     For Each resource As Capacity In dtoObj.listcapacityresponse.capacity 

    If resource.type = 0 Then 
       Dim memoryusedpercent As String = resource.percentused 
      ElseIf resource.type = 1 Then 
       Dim cpuusedpercent As String = resource.percentused 
      ElseIf resource.type = 3 Then 
       Dim pristorageusedpercent As String = resource.percentused 
      ElseIf resource.type = 5 Then 
       Dim mgmtippercent As String = resource.percentused 
      ElseIf resource.type = 6 Then 
       Dim secstoragepercent As String = resource.percentused 
      ElseIf resource.type = 8 Then 
       Dim guestippercent As String = resource.percentused 
      End If 

     Next 

구문 분석이 끝나면 if 문 내의 각 변수가 채워질 것으로 예상됩니다 (단지 현재는 %에 관심이 많습니다). 대신 빈 변수와 오류가 발생하지 않습니다.

내가 뭘 분명히 놓치고 있습니까?

내 프로젝트의이 비트를 얻기가 필사적이며, 이것이 내 방식으로 서있는 마지막 것입니다!

도움이되었습니다! :)

+1

변수가 If 문 외부에서 범위를 벗어납니다. 당신이 루프를 시작하기 전에 그 나쁜 소년들을 어둡게하고 값을 가져야합니다. – N0Alias

+0

아 내가 문자열 = "" 공공 mgmtippercent으로 " 공공 pristorageusedpercent 문자열 =" "문자열 =으로 공공 cpuusedpercent"다른 이름으로 ... 그러나 내가 맨 위에 다음, 나는 그 변경을 의미, 공공 memoryusedpercent 참조 As String = "" 공용 secstoragepercent As String = "" public guestippercent As String = "" 그래서 나는 그것이 충분하다고 생각했을 것입니다. 나는 지금 그들을 정리하고 다시 시도 할 것이다 – John

+0

아아아, 참으로, 일단 내가 그들을 정돈하면 나는 기대하고있다. 친절하게 감사합니다! 관심있는 사람들을위한 – John

답변

0

변수가 If 문 외부에서 범위를 벗어납니다. 루프 위의 그들을 희미해라. 그러면 당신은 잘되어야한다.

관련 문제