1

I have a Json string which contains space in its property name. Now how I should do that. I searched and found the following answer.

public jsonClass 
{
   [JsonProperty(Name="Space Property")]
   public string SpaceProperty {get; set; }
}

But it seems like I've to use json.net library to achieve this.

Is there a way that I can achieve the same thing with the use of wp8 inbuilt datacontract json serializer dll?

Thank you.

2 Answers 2

3

DataMemberAttribute has a Name property.

[DataContract]
public jsonClass 
{
   [DataMember(Name = "Space Property")]
   public string SpaceProperty { get; set; }
}
Sign up to request clarification or add additional context in comments.

Comments

2
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;

DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(jsonClass )); 
MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(jsonString)); 
jsonClass obj = (jsonClass )ser.ReadObject(stream);

Read here, how to deserialize without using Json.Net

http://code.msdn.microsoft.com/Json-Parsing-in-windows-74d89955

Serialize and Deserialize JSON Data

3 Comments

I think i didn't make my question clear. I'm already using this method. BUt in my Json string I've a property name with space in it. So I need to know how to declare the object for that property.
what you have declared is the way to declare a property with space!
But I need json.net for this right ? Can I not do this with the inbuilt json classes itself ?

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.