I am trying to parse json data for reddit comments in a Windows 8 Metro app. I have been able to successfully parse the homepage json data using JSONObject.Parse(), but when trying to parse data for a comments page, the parse failed. The data in question is here:
Homepage: Can Parse
http://jsonviewer.stack.hu/#http://www.reddit.com/.json
Comments: Cannot Parse
http://jsonviewer.stack.hu/#http://www.reddit.com/r/leagueoflegends/comments/vt3wk/proving_grounds_playable_on_live_on_all_3_regions/.json
The problem appears to be that the root object of the comments json is an array, while the root object of the homepage is a normal object. However, jsonlint.com tells me that the json is valid in both cases.
Can anyone tell me why this occurs?
I found the answer. Instead of JSONObject.Parse, JsonArray.Parse had to be called.
Related
I am using a web api which takes XML as in body content, but Now i want to send Json in body content.
But when i have tried sending json in body it is giving me parent window control error.
Any Suggestion will be helpful for me.
Thanks in advance !!
Nitesh, to easily help you, kindly share a code snippet or snapshot of the code you are trying to execute.
Alternatively, from the abstract point of view, I suggest that you add "Content-Type" header key with a value of "application/json" to specify to the API server that the content is of a JSON format.
For more information about Content Type, I recommend reading the article about content-types https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type
Thank you
I making a Windows 10 Universal App to connect to my database and display the table. I build sort of a API on my server that if called it returns mysql table data in json. Now, this received json data wont be always the same, so I want to display whatever table from my database on my server, by record. So that it will show only one record at the time, and when you press forward it will go to the next record. I can figure this out on my own(the buttons). But I don't know how to deserialize the unknown json data (which will be always different from table to table) and display it on table by record. I tried the Dictionary<> deserialize but it gave me an error, that the received string json must be a json object, which I later converted it to but it still wasn't working. I doing this just for learning and personal project. If anyone know's a solution it would be great.
#David, I suggest you using the JSON.NET library to de-serialize the JSON string to Dictionary.
You can easily add a JSON.NET reference from the NuGet in Visual Studio.
string json = #"{""key1"":""value1"",""key2"":""value2""}";
Dictionary<string, string> values = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
How can I send some object, say a JSON object, from JavaScript to my C# code for windows phone app?
I know of window.external.notify function. But this can send only string as a single parameters.
What if I want to send two different parameters?
To try answer your json question, why not serialize your object into a json string. I like to use NewtonSoft.Json to do that. Google for it or pull down with nuget. It is supported for Windows phone
This question already exists:
WinForm button click event to convert c# data to html code? [closed]
Closed 9 years ago.
I have been trying to find a way or code that will convert c# data to html code/html template by a ButtonClick but have just found some converters that convert C# code to HTML code and thats not what i need. Its by a ButtonClick that i need C# data that is filled in by users in the program this data is texts and images. Cant provide any code cause i only got the front end UI designed nothing else and i got to low reputation to upload a pic =)
P.S i am a noob at C# done some things in C# in the past but have forgot alot when i havent been working with it for years.
I have a hunch that you are attempting to submit data from your server side to a client side web page via POST.
If this is the case, the stages would be as follows:
The web page will send a request to the server. You might want to use a full postback or an ajax call. If you are a newbie, the full postback would be easier for you.
The Server side will fetch required data (the C# data).
The server will wrap up the C# data to a structure that can be parsed by the client side.
The server will send the wrapped up data back to the client.
Details:
The part you asking about is #3 (wrapping up the data to a structure that can be parsed by the client side ).
In order to do so I suggest using a JavaScriptSerializer as described in this SO thread (including code example...).
In case your data is an object that has many redundant properties that are not required by the client side, I would also consider using anonymous types for sending only required data. You can find an example for how to do this here
So here's the situation: I have a friend who wants me to make an app for his comic website, he wishes for me to set it up so the comics appear in a tab (navigation and tablelist/view). Im not sure what the best method for his XML file is, i do know of the xml code on how do it, but unfortunately, i do not know nor have ever used the code for it.
so im sorta lost, this is the file: http://hoshen.controlshiftblack.com/HoshenFeed.xml
And does anyone have any simple to use suggestions for using XML in an app?
There are saveral ways to get the job done, you can use an xml library and make a parser for your xml feed like
NSXML
http://deusty.blogspot.com/2008/09/nsxml-on-iphone.html
or libxml
http://iphonedevelopment.blogspot.com/2008/04/simplifying-libxml.html
Also there are third party parsers that allow you to use Objective-c objects, one widely used is
GData
http://feedproxy.google.com/~r/RayWenderlich/~3/YuSy-Gey1sg/how-to-read-and-write-xml-documents-with-gdataxml
If that's not enough, ask your friend to send you JSON data instead and use a JSON library for iPhone
http://maniacdev.com/2010/07/using-objective-c-json-to-do-translations-in-an-ios-app/