JSON deserialization query - windows-phone-7

I'm trying to deserialize a JSON string with the following syntax into C# classes, but I'm sort of puzzled on how to handle the dynamic nature of the "parent" object:
{"1":[{"id":"12139811","num":"37805729","date":"2012-01-30"},{"id":"12139812","num":"36911026","date":"2012-01-30"}],"2":[{"id":"12158366","num":"17582898","date":"2012-01-30"},{"id":"12207165","num":"38493538","date":"2012-01-30"}]}
Any help on what the classes should look like will be appreciated.
(Preferably the syntax to Deserialize would be something like
var objects = JsonConvert.DeserializeObject<List<MyObject>>(jsonString);

I think is beacuse your Json star with and identifier "1" instead of the array...
so you could try this
var objects = JsonConvert.DeserializeObject<Dictionay<Object,List<MyObject>>>(jsonString);

Related

parse out JSON.parse(cookies[:cookie_name]) item into ruby variable

I need to access a specific string inside the cookie.
I am using:
#id = JSON.parse(cookies[:cookie_name])
and it returns a JSON object. What is the best way to access a specific item in the JSON object?
Here is example of the JSON object:
{"distinct_id"=>"12345", "$initial_referrer"=>"$direct", "$initial_referring_domain"=>"$direct", "__mps"=>{}, "__mpso"=>{}, "__mpa"=>{}, "__mpap"=>[], "mp_name_tag"=>"12345", "id"=>"12345"}
What I want from that object is the distinct_id.
Any direction would be great.
That looks more like a Ruby hash than a JSON object (JSON.parse returns a hash as well). If that's the case, wouldn't #id['distinct_id'] work?

Can't convert string to integer ruby error when accessing Hash/Array

I am new to ruby. So I was trying to get data from my data array but I get a "can't convert String into Integer" error.
The way I am accessing data is
data["myobject"]
It seem that data is an array, not a hash.
I think data looks like this :
data=['foo', 'bar']
instead of looking like this :
data={'myObject'=>'foo', 'myObject2'=>'bar'}
So try to change data or retrieve data by its index
data[0]

how to send regex to server side in meteor

In my application, I'm building a query object some thing like below
Object {pointType: /analog/i, _id: Object}
I tried to store it in session variable,
Session.set("currentPointsQueryObject",queryObj);
Then on click event I'm getting this object
var res= Session.get("currentPointsQueryObject");
console.log(res);
but here I'm getting like below
Object {pointType: Object, _id: Object}
Meanwhile, I sent group_id to the server
by geting it from session variable like
var group_id=Session.get("currentGroupId");
which is working fine(it is displaying id in server log)
Then, I've tried storing it in global variable, which returning as expected
like below on click event
Object {pointType: /analog/i, _id: Object}
but when I sent it to server side method (Immediate line after console.log() )
Meteor.call("updateGroupPoints",res,function(err,data){
console.log("updated points");
console.log(data);
});
when I log res in server console, it is showing
{ pointType: {}, _id: { '$nin': [] } }
Althoug I have something in pointType, It is not passed to the server.
Anyone had idea, Is this the thing related storing?
You cannot directly serialize RegExp to EJSON, but you can:
var regexp = /^[0-9]+$/;
var serialized = regexp.source;
Send serialized and then deserialize:
new RegExp(serialized)
Take a look at : Meteor: Save RegExp Object to Session
/analog/i is a regular expression, right? Values stored in Session and values sent to methods must be part of EJSON values. Regular expression aren't.
There's a handy way to teach EJSON how to serialize/parse Regular Expressions (RegExp) as of 2015 documented in this SO question:
How to extend EJSON to serialize RegEx for Meteor Client-Server interactions?
Basically, we can extend the RegExp object class and use EJSON.addType to teach the serialization to both client and server. Hope this helps someone out there in the Universe. :)
Simply stringify your RegExp via .toString(), send it to the server and then parse it back to RegExp.

Mapping a JSON array of unnamed values with RESTKIT 0.20

When I configure mapping from a REST service returning JSON to a object, I normally do this:
RKObjectMapping *myMapping = [RKObjectMapping mappingForClass:[MyClass class]];
[myMapping addAttributeMappingsFromDictionary:#{#"Address" : #"address", #"City" : #"city"}];
and this works great for JSON with named attributes, but how do I map the following JSON to a object with the property "name"?
["My Value","Some other value","More stuff","Hello World"]
This JSON is just a array of values and has not name/key only values. How do I map this to a object with RESTKIT 0.20?
Thank you
Søren
This expression in square brackets is a json array: http://www.json.org. If you look on the syntax tree on the home page, you can consider, every json array is a value of a "variable" with a name. It means your expression has to look like this, to be a valid json:
{ "myArray": ["My Value","Some other value","More stuff","Hello World"] }
and you map it like you always do:
[myMapping addAttributeMappingsFromDictionary:#{#"myArray" : #"myArray"}];
Your parameter MyArray in mapping target class has then a type of NSArray.

how to send a JSON object from contentURL : data.url("foo.html") to contentScript

I tried using window.postMessage but this only sends a variable (containing string) to the contentScript. But I want to send a number of variables' values. This seems to be possible by using a JSON object.
Simply use JSON.stringify() to turn the object into a string:
var data = {a: 1, b: 2};
window.postMessage(JSON.stringify(data), "*");
On the other end use JSON.parse() to reverse the process:
var data = JSON.parse(message);
If you use:
self.port.emit('some-event', object)
...and only send objects that can be serialized into JSON properly, the SDK will handle serialization and parsing for you. Here's a quick builder example that illustrates this:
https://builder.addons.mozilla.org/addon/1036506/latest/
I had thought that postMessage would be the same?

Resources