JSON Deserialzer error

  • Thread starter Thread starter Rajiv Verma
  • Start date Start date
R

Rajiv Verma

Hi,
I am using .NET 3.5 JSON deserializer. When I am passing my JSON server
response to DataContractJsonSerializer,

DataContractJsonSerializer ser = new
DataContractJsonSerializer(typeof(Envelope));

It is throwing an exceptions "Expecting state 'Element'.. Encountered 'Text'
with name '', namespace ''. error?"

I am not sure what is going wrong, I am passing it a valid JSON string and
string in the error message ", namespace " is not part of JSON string, I
don't know why is deserializer throwing this error. And what is about
"Expecting state" in JSON deserializer.

Please help me out, thanks in advance.
 
Rajiv,

Without seeing the string that you are passing to the serializer, how
you are calling the serializer, and the definition of the Envelope class,
it's impossible to say.
 
Rajiv Verma said:
Hi,
I am using .NET 3.5 JSON deserializer. When I am passing my JSON server
response to DataContractJsonSerializer,

DataContractJsonSerializer ser = new
DataContractJsonSerializer(typeof(Envelope));

It is throwing an exceptions "Expecting state 'Element'.. Encountered
'Text'
with name '', namespace ''. error?"

I am not sure what is going wrong, I am passing it a valid JSON string and
string in the error message ", namespace " is not part of JSON string, I

Single quotes, not double.

The error message is roughly:

Expecting state '%s'.. Encountered '%s' with name '%s', namespace '%s'.
The first insertion field is "Element", the second is "Text", the third and
fourth are both empty strings.

Basically some element is spec'ed in the schema to contain only other
elements, but you've got some loose text inside (possibly even whitespace).

Can you run something through the other way and see what it produces, then
compare? Maybe your javascript snippet is supposed to be wrapped inside a
don't know why is deserializer throwing this error. And what is about
"Expecting state" in JSON deserializer.

Parsers are often designed as finite state machines.
 
Back
Top