tags:

views:

142

answers:

3

Hi guys , in the following code This is what i do ,

private Speed string[] { get; set;} 
internal speed duration.slow 
public setspeed { get {  return speed } set { speed = value;
string temp = "{ duration :"+speed.tostring()+"}";
this.Speed = new string[] {temp};
} }

the properties are all appended to the script in terms of "atribute : value " ,

the problem that i get (the output not debugger) is $("#Id").tabs({ fx: ["{duration:'slow'}"] }); because of the double quotes the jquery doent work

+2  A: 

Your Speed property (or field) is an array, not a single string.

You don't really have any output yet. If you're converting the whole array into a string, that's where the problem is. If you're just looking in a debugger, that's not really output - it's showing you that you've got an array which contains a string.

Please give us more information about what you're doing with the value, and we may be able to help you fix whatever's wrong.

EDIT: To respond to your edit, your description still isn't clear:

the properties are all appended to the script in terms of "atribute : value "

What do you mean by "in terms of"? Please show the code. It looks like you're getting a reasonable representation of a string array, but that that's not what you really want - which suggests that whatever mechanism you're using to add the values to the page isn't appropriate.

Jon Skeet
Post this as an edit to your question and remove this from the comment section.
rahul
i think the problem is due to the fact i Serialize the output , is it why that the double quotes still appear in the output?
rahul
@rahul: Quite possibly, but you still haven't shown *how* you're doing it.
Jon Skeet
A: 

the curly braces "{" and "}" are used for formatting strings. If you do not want to do this, double them to escape them:

string temp = "{{ duration :"+speed.tostring()+"}}"
Marc Wittke
No, that's only if you use string.Format, which he doesn't do.
erikkallen
A: 

I think the issue is your serialisation to JSON.

You have a string[], so

string[] items = new string[] { 
    "{ duration :'fast'}",
    "{ somethingElse : 'as an example'}" 
};

This serialises (correctly) to JSON as:

var jsonArray = ["{ duration :'fast'}", "{ somethingElse : 'as an example'}"];

I think what you want here is actually:

var jsonObj = { duration :'fast', somethingElse : 'as an example' };

So you either want to literally write out your string[], something like:

$("#Id").tabs({ fx: [<%=string.Join(",", items ) %>] });

Or you want to create a Dictionary<string,object> or new anonymous type and serialise that instead:

var items = new { 
    duration = "fast",
    somethingElse = "as an example"
};

Also, avoid array properties: http://msdn.microsoft.com/en-us/library/k2604h5s.aspx

Keith
Wow Thanks a lot , actually the serialisation is done in the base class which i dont have access to hence i was not able to provide a clearer picture but still u were right on the needle , i have been spending 6hrs to figures this out , thanks keith (the last one is best suited )
rahul
You're welcome, happy to help. Assuming that you're happy with it use the green tick on the left to accept this answer.
Keith