9

Hi I have an array of dynamic type which i want to iterate through. But when i say arrayObject.lenght, i get following error:

'object' does not contain a definition for 'length' and no extension method 'length' accepting a first argument of type 'object' could be found

how do i iterate over the array?

[Update]

I post a custom json object using jquery ajax and i have written a model binder for untyped JSON. Here is a screenshot:

enter image description here

1
  • Maybe you can show some code of what exactly you are doing? Commented Dec 19, 2011 at 18:23

2 Answers 2

32

Found the solution:

foreach (dynamic item in cartJsonObject)
{
   // code here
}

I was trying with for loop and foreach using var type. Changing it to dynamic solved it.

Sign up to request clarification or add additional context in comments.

1 Comment

To make this work you may need to add a Reference to "Microsoft.CSharp".
0

This error very likely means that what you have is not an array but another collection - IEnumerable would be my best guess. You can use the Count() extension method provided by Linq to retrieve the number of elements.

1 Comment

'object' does not contain a definition for 'Count' and no extension method 'Count'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.