0

I have a question about parsing JSON data with JScript .NET, 4.0. I am using Visual Studio 2005 running in Windows XP to make a Windows form (as opposed to a website).

My RESTful API calls return JSON data in the form of an array of objects, for example:

[{"country": "USA", "state": "CA", "city": "San Francisco”}, {“country”: “USA”, “state”: “WA”, “city”: “Seattle”}, {"country": "USA", "state": “MA", "city": “Boston”}], 

and I don’t know how to parse it into a usable object. I think I need something like a serializer/deserializer, like DataContractJsonSerializer to do this, see MSDN, but am having difficulty implementing it in JScript .NET 4.

1
  • If you still need it, see this answer for an easy way to import JSON methods from the htmlfile COM object. Commented Jan 21, 2016 at 5:17

2 Answers 2

0

I'm not sure if you've already moved on from this, and I probably need more information to help, but I have a collection scripts that serve as a library to do common things in the jscript. One common task is I might make call from one of these scripts to some api and get json back. In order to parse it, I went to json.org and downloaded json2.js. Once I got that, I'm able to call:

var data = JSON.parse(string_from_api)

Just as I would in javascript on a modern browser. I included json2.js in the same directory as all my other scripts in the library. The problem is that JScript.net (to my knowledge) doesn't have the JSON object that is in modern browsers. You have to add it yourself. Once you do, you can take advantage of the JSON object serialization and deserialization it offers.

Sign up to request clarification or add additional context in comments.

Comments

-1

This is what I've done!

var cfg = eval('('+File.ReadAllText(Directory.GetCurrentDirectory()+"\\Config.json")+')');

Directory.GetCurrentDirectory() is by path applicacion

File.ReadAllText(...) is by read File json

eval('('+ $$ +')') .. Eval.. XD

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.