Using JSON.NET To Parse JSON Generated Through PHP?
Mar 2, 2010
I'm sure this has been asked before but I'm not finding quite the information I'm needing so I thought I'd post this.
I've written a PHP script that returns a simple JSON object that looks like this:
{"status":"success","level":"admin"}
I'm doing a standard web request that submits the required data to the script over the internet and that's working fine.
Now, I want to use JSON.NET to pull out the individual variables so I can know what the values of "status" and "level" are. The problem is, I have no idea where to start.
I'm doing this in VB.NET (on the .NET Compact Framework).
I am been stuck on this for 3 days now...I have been accessing the twitter api to pull a user_timeline for a list of users and the json that comes back is impossible to work with. I tried to deserialize it using javascriptserializer and get an error:invalid object passed in , ':' or '}'
Now this is frustrating since I expect the json being returned to be error free. Then I tried json.net and split the posts using string.split and tried to convert each post to Jobject or jarray. for Jarray I get
'unexpected end of content while loading jArray
[Code]...
Now I have formatted the code here and not pasted the whole file but it does look like valid json to me and I do not alter anything after receiving the stream from the twitter api. Can someone please point me in the right direction? I really need to get this stuff parsed?
how to receive and send back json. Hope someone can help me on this. I understand by examples.
On my clientside, I am sending a ajax json string "name":"theName" to the server side and would like the server side to return a string saying "welcome &name ".
{"AliasName": "ysiCountryInfo", "DataClass": {"Description":"United States 111","Code":"usa","WriteOffTaxPointAdjustment":0,"IndexationRounding":6}} I would like to deserialize object into below class
I have a JSON response from a web service that I need to be converted to an object then to an array. My response is similar to the one below:
{"status":{"error":"NO","code":"200","description":"none","message":"Request ok"},"geolocation":{"lat":"38.89515","lng":"-77.0310"},"stations":[{"country":"United States","regPrice":"0.00","midPrice":"0.00","prePrice":"0.00","streetAddress":"1401, I St[code]....
I am doing this is VB.NET within a console for now. Basically I am trying to create a simple way to test my API calls and output the information. What I am trying to accomplish is having to loop through the JSON array and list the stations.
I'm writing a little web service which generates SO/SF/SU/MSO user flair in the form of an image with various "themes". I find this preferable to using the HTML/JS solutions offered by SO as it's more flexible and also works better in forum signatures.
I'm retrieving the data using the apparently unofficial API (More info here). I can have the data in HTML or JSON. I assumed the JSON would be easier to parse.
Unfortunately, I'm not great at regexes. and the best I can come up with is some very hacky sub-stringing. I believe a regex should be the most elegant solution
regex that matches ID, GravatarURL, ProfileURL, DisplayName, Reputation and Badge Counts (Bronze/Silver/Gold).
FWIW This is to be used in a VB.Net project (in case that affects the syntax at all)
[Code].....
In case any of you are interested, some screenshots of the flair as a work in progress are available here: Me, Jeff Atwood, Joel Spolsky
how to parse and extract specific elements out of a JSON that I obtain from a web source. Using Visual Studio 2010 and VB. I can get the JSON but I haven't been able to find any examples or tutorials regarding parsing the data, locating specific elements and their associated data.
How can I convert a JSON string to an array OR a JSON string to XML in VB.NET? I know how to do this in C#, as I have read dozens of articles on it, however, I am unable to figure out how to achieve the same result in VB.NET.
I'm using the System.Web.Script namespace via System.Web.Extensions.dll (from Microsoft).
I'm willing to use an additional DLL file if needed.
I am accessing the facebook api and using the json.net library (newtonsoft.json.net)I declare a Jobject to parse the content and look for the specific elements and get their values. Everything works fine for the first few but then I get this unexplained nullexception error " (Object reference not set to an instance of an object)Now I took a look at the declaration but cannot see how to change it. Dim jobj as JObject = JObject.Parse(responseData) message = jobj("message").tostring
The error occurs at the last line above.I check to see if message is null and then look for the next desired field as follows
[Code]...
This is one example where "message" does not appear in the first few lines but appears later. So what I do is look for position of message and description and which ever is first go and get that and if I get an error or the fields do not return anything, I try and parse by regex and even that is not working right.
I have two experimental web services. One is an asmx contained within a .net web application. The other is a WCF service library being invoked from the web application.The asmx basically does everything I need, but I think WCF would be better, except that it doesn't do anything as I would expect after fiddling with the asmx service.For example, the same method behaves differently in each:
' ASMX <WebMethod(BufferResponse:=True, EnableSession:=False)> Function Test(aObject as Object) as Object ' object will have been successfully serializaed into a dictionary
I have to send a request to Webservice and I have a working PHP solution, that I have to translate in VB.net
Here's the code working in PHP
//fill in the details of the contacts.userId is obtained from loginResult. $contactData = array('lastname'=>'Valiant', 'assigned_user_id'=>$userId); //encode the object in JSON format to communicate with the server.
[code]....
Naturally I imported a reference to a Json library and Imported (Imports Newtonsoft.Json)?
I'm trying to understand how to actually use, and create JSON data.
StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); using (JsonWriter jsonWriter = new JsonTextWriter(sw))
[code]....
and I am sure it does... but how do I view it? How do I turn that into an object that the browser can output.It seems to me that the first stage I need to resolve is "how to create" JSON files/strings, next stage will be how to actually use them. If it helps answer the question, what I'm aiming for initially is to be able to use AJAX Autocomplete from a search page generated from my MySQL database, I was hoping I could write a simple SQL query and have that returned using something similar to the above?
Alright I have been trying to figure this out and I read the MSDN page on the JavaScriptSerializer. However, I still can't figure out how to get this to work on an asp.net page. I want to convert my dataset into a json string so I can graph it using FLOT(graphing tool) imports System.Web.Script.Serialization
dim myObject = dataset.getxml()dim jsonString = new JavaScriptSerializer().Serialize(myObject)
I'm trying to figure out how to do SQL queries towards an SQL 2005 Express server and format the return value to JSON. I got the queries working using this (perhaps very newbie-like) code;
Imports System Imports System.Data Imports System.Data.SqlClient Imports System.Web.UI
I am trying to call a rest service..that service returns json object...I am able to send the request but unable to serialize the json...here is the code i am trying
I have an assigment where I must send queries to the database and the returns data. I would like to convert that data to a json and then use it with jQuery
My idea is make an array (żarrayList?) and then convert it to json.
How can i use json with asp.net vb? I'm not allowed to use a webservice yet
I am trying to deserialize a JSON string using VB.net and cannot seem to pull the values out of the finished List.[code]I am told "Index was out of range. Must be non-negative and less than the size of the collection."
I am generating this with asp.net (vb.net) from data stored in a database. I think I need to somehow escape the double quotes within the content section of the json data. How do I do this?
I have the following code which serialize an array to json:
Dim col1 As New ArrayList Dim col2 As New ArrayList objJSONStringBuilder = New StringBuilder() objSQLConnection = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("connString")) objSQLCommand = New SqlCommand("select col1, col2 from table1", objSQLConnection) objSQLCommand.Connection.Open()