PC Review


Reply
Thread Tools Rate Thread

Complicate json object?

 
 
Billy Zhang
Guest
Posts: n/a
 
      13th Aug 2008
I have a asp.net app, in client I create a Complicate json string,
for example: { a: ‘a’, b : { b ; ‘b’ } }

If .net has corresponding type, it could be
deserialized, for example:

DataContractJsonSerializer serializer = new
DataContractJsonSerializer(typeof(A));
using (MemoryStream ms = new
MemoryStream(Encoding.Unicode.GetBytes(jsonText))) {
//serializer.WriteObject(ms);
//return Encoding.Default.GetString(ms.ToArray());
A a = (A)serializer.ReadObject(ms);
return a;

}

But the question is if there are no corresponding .net type, in .net 3.5
could we serialize it into anonymous type? Or any other way to solve this
problem?

-Billy zhang
 
Reply With Quote
 
 
 
 
Steven Cheng [MSFT]
Guest
Posts: n/a
 
      13th Aug 2008
Hi Billy,

As for the WCF JSON serializer, I'm afraid so far it doesn't support
serialization upon anonymous type. Actually all the .NET serialization
formatter cannot serialize with anonymous type. I've tried directly
serialize it via the following code but it report a type is not serialable
error:

====================
var obj = new { Name = "abc", Title = "abc" };

DataContractJsonSerializer jsonserializer = new
DataContractJsonSerializer(obj.GetType());

MemoryStream ms = new MemoryStream();
ms.Close();

jsonserializer.WriteObject(ms, obj);
=========================

Also, anonymous's autogenerated type name is random(based on runtime,
appdomain info) which is not reliable and persistable in districuted
environment. For your scenario, if you have some complex data blocks which
will be constructed on the fly(without an existing definted type), I think
it would be better to manually pass the data as string parameter and
manually parse it in code. How do you think?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we

can improve the support we provide to you. Please feel free to let my
manager know what you think of

the level of service provided. You can send feedback directly to my manager
at: (E-Mail Removed).

==================================================
Get notification to my posts through email? Please refer to

http://msdn.microsoft.com/en-us/subs...#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response

from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take

approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution.

The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump

analysis issues. Issues of this nature are best handled working with a
dedicated Microsoft Support

Engineer by contacting Microsoft Customer Support Services (CSS) at

http://support.microsoft.com/select/...tance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.



--------------------
>From: =?Utf-8?B?QmlsbHkgWmhhbmc=?= <(E-Mail Removed)>
>Subject: Complicate json object?
>Date: Tue, 12 Aug 2008 18:48:09 -0700


>
>I have a asp.net app, in client I create a Complicate json string,
>for example: { a: ‘a� b : { b ; ‘b�} }
>
>If .net has corresponding type, it could be
>deserialized, for example:
>
>DataContractJsonSerializer serializer = new
>DataContractJsonSerializer(typeof(A));
>using (MemoryStream ms = new
>MemoryStream(Encoding.Unicode.GetBytes(jsonText))) {
> //serializer.WriteObject(ms);
> //return Encoding.Default.GetString(ms.ToArray());
> A a = (A)serializer.ReadObject(ms);
> return a;
>
>}
>
>But the question is if there are no corresponding .net type, in .net 3.5
>could we serialize it into anonymous type? Or any other way to solve this
>problem?
>
>-Billy zhang
>


 
Reply With Quote
 
Steven Cheng [MSFT]
Guest
Posts: n/a
 
      15th Aug 2008
Hi Billy,

Is there anything else we can help on this?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we

can improve the support we provide to you. Please feel free to let my
manager know what you think of

the level of service provided. You can send feedback directly to my manager
at: (E-Mail Removed).

--------------------
>X-Tomcat-ID: 2894094
>From: (E-Mail Removed) (Steven Cheng [MSFT])
>Organization: Microsoft
>Date: Wed, 13 Aug 2008 03:38:58 GMT
>Subject: RE: Complicate json object?


>Hi Billy,
>
>As for the WCF JSON serializer, I'm afraid so far it doesn't support
>serialization upon anonymous type. Actually all the .NET serialization
>formatter cannot serialize with anonymous type. I've tried directly
>serialize it via the following code but it report a type is not serialable
>error:
>
>====================
> var obj = new { Name = "abc", Title = "abc" };
>
> DataContractJsonSerializer jsonserializer = new
>DataContractJsonSerializer(obj.GetType());
>
> MemoryStream ms = new MemoryStream();
> ms.Close();
>
> jsonserializer.WriteObject(ms, obj);
>=========================
>
>Also, anonymous's autogenerated type name is random(based on runtime,
>appdomain info) which is not reliable and persistable in districuted
>environment. For your scenario, if you have some complex data blocks

which
>will be constructed on the fly(without an existing definted type), I think
>it would be better to manually pass the data as string parameter and
>manually parse it in code. How do you think?
>
>Sincerely,
>
>Steven Cheng
>
>Microsoft MSDN Online Support Lead
>
>
>Delighting our customers is our #1 priority. We welcome your comments and
>suggestions about how we
>
>can improve the support we provide to you. Please feel free to let my
>manager know what you think of
>
>the level of service provided. You can send feedback directly to my

manager
>at: (E-Mail Removed).
>
>==================================================
>Get notification to my posts through email? Please refer to
>
>http://msdn.microsoft.com/en-us/subs...#notifications.
>
>Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
>where an initial response
>
>from the community or a Microsoft Support
>Engineer within 1 business day is acceptable. Please note that each follow
>up response may take
>
>approximately 2 business days as the support
>professional working with you may need further investigation to reach the
>most efficient resolution.
>
>The offering is not appropriate for situations
>that require urgent, real-time or phone-based interactions or complex
>project analysis and dump
>
>analysis issues. Issues of this nature are best handled working with a
>dedicated Microsoft Support
>
>Engineer by contacting Microsoft Customer Support Services (CSS) at
>
>http://support.microsoft.com/select/...tance&ln=en-us

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
complicate query? hoachen Microsoft Access Queries 3 17th Feb 2010 06:17 PM
Complicate function Sakis Microsoft Excel Misc 9 5th Dec 2007 04:52 PM
Convert Class Object to JSON string? quantass Microsoft C# .NET 1 16th Jan 2007 09:10 AM
Maybe too complicate Tom Microsoft Access 4 5th May 2006 05:50 PM
A complicate database Amy Microsoft Access Getting Started 1 15th Oct 2003 12:44 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:18 PM.