0

I can't seem to access an item 0: Watch Experession .

I have tried a number of different ways to access ComID, such as:

 ComID = response.Result.PartData.PartList.PartDto.Item(0).ComID  OR
 ComID = response.Result.PartData.PartList.PartDto.(0).ComID      OR
 ComID = response.Result.PartData.PartList.PartDto.0.ComID

This works all the way up to PartDto, but I'm just struggling to access Item 0.

My backup solution is to loop through each item in PartDto, which can work, but there's got to be a better way.

Thanks for your help!

Mark
  • 13
  • 1
  • 3
  • 1
    If you're drilling into a series of nested dictionaries or collections wouldn't each have to be referenced as an item of the parent like you are referencing item(key 0)? –  Jul 11 '18 at 22:52
  • You should apply some context to your post. I'm assuming that `response` is `responseText` which is a JSON string converted by a library. My answer to [Using VBA and VBA-JSON to access JSON data from Wordpress API](https://stackoverflow.com/a/51128453/9912714) would probably work. – TinMan Jul 11 '18 at 22:55
  • 1
    @TinMan I'm not a VBA expert, so thanks for your patience. I have tried: `ComID = response.Result.PartData.PartList.PartDto(1).ComID` and `ComID = response.Result.PartData.PartList.PartDto.Keys()(1).ComID` and neither of those worked. – Mark Jul 11 '18 at 23:17
  • @Jeeped asked that question. You should review my post. What does `TypeName(response.Result.PartData.PartList.PartDto)` return? – TinMan Jul 11 '18 at 23:22
  • @TinMan "JScriptTypeInfo" – Mark Jul 11 '18 at 23:25
  • Yeah, 'Set scriptControl = CreateObject("MSScriptControl.ScriptControl") scriptControl.Language = "JScript" Set Response = scriptControl.Eval("(" + sRespText + ")")' – Mark Jul 11 '18 at 23:32
  • Working with the `JScriptTypeInfo` is a little tricky but I created a function that convert the JSON string into a usable object [Function to Return a JSON Like Objects Using VBA Collections and Arrays](https://codereview.stackexchange.com/q/196482/171419). – TinMan Jul 11 '18 at 23:37
  • You should know that the `ScriptControl` is not supported by 64 bit systems. You should probably use the library from the first link that I posted in conjunction with my answer to that link. – TinMan Jul 11 '18 at 23:41
  • Make sure and use @TinMan to target your comments to me. – TinMan Jul 11 '18 at 23:48

0 Answers0