Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am a Jscript.net newbie i am trying to read an object I do not k now exactly what the object x is.
in fact i read some other valeus successfully from a sharepoint site, but it turns out the only variable that fails is x, it turns out that x is an object. At first i thought [object Object] didnt return anything untill i did a network trace; the values of x seam to be encapsulated inside an object. But i dont know how to get my values out of an object.

if i do
JavaScript
alert(x);

I get result : [object Object]

if i do
Java
alert("myObject is " + x.toSource());  // but this works only in firefox 

I get result : ({$L_1:3, $b_1:"tpc-102"})


What i want to get in return is just these values.
And working in not only firefox also internet explorer

3
tpc-102

preferably having some variables assigned to them like
a = 3
b = tpc-102



If you like to answer this help me to get these values out; pointing me to many websites and books is maybe an idea for later; i'm not afraid of learning but i consumed a lot books allready in none of these i found the [object Object] problem. And even looking with google didnt gave me clues.
Posted
Updated 2-Nov-11 14:12pm
v5
Comments
AspDotNetDev 2-Nov-11 20:47pm    
I recommend using a JSON stringify method or one of the reflection methods SAKryukov posted links to. You might also want to use the Chrome debugger. Or you could use FireFox since it seems like you just need the info to debug.
PGT 3-Nov-11 11:56am    
Okay.. stringify is i think for now the easiest method.
But there might be more methods, as one would think especially in sharepoint that there would be buildin functions.

Anyway, there is more...
Apparently JSON has been added to Internet Explorer since version 8.
And starting from i think IE7, one can define the document mode for IE browsers. So JSON only works correctly in Internet Explorer if the document IE mode is set to at least IE8
So to use JSON inside the header the following meta tag is required.

<meta http-equiv="X-UA-Compatible" content="IE=8" >

Firefox just works, doesnt care about it.
But this was the main reason why i couldnt handle the returned objects.

1 solution

First of all, why did not you explain what x is? If this is the object of your class, you should have better show the code, how did you get this object.

Then, if you know what to expect from this object from your own code or documentation, you could just call its methods and properties.

Finally, if you don't have this information, with JavaScript you can use Reflection (http://en.wikipedia.org/wiki/Reflection_(computer_programming)[^], http://en.wikipedia.org/wiki/Reflection_%28computer_programming%29#ECMAScript[^]) and find out all object's members. See:
http://lpetr.org/blog/archives/reflection-in-javascript[^],
http://stackoverflow.com/questions/275351/javascript-reflection[^],
http://stackoverflow.com/questions/5208784/reflecting-within-a-javascript-function[^],
http://stackoverflow.com/questions/7447117/javascript-reflection-to-find-prototype-methods-global-scope-methods-and-object[^].

—SA
 
Share this answer
 
Comments
PGT 3-Nov-11 11:58am    
See my answer to AspDotNetDev;
I am not sure who to credit for this, because i tried so many solution before asking it here, and i only was in the wrong document mode for IE.
I had tried JSON.stringify before too

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900