Skip to main content

How to Convert JSON String to JSON Object using JavaScript

In our previous post we have seen compilation error related stuff, In this article we will see “How to Convert JSON String to JSON Object using JavaScript

In JavaScript there is a method called JSON.parse() to convert JSON string into JSON object. JSON is a commonly used data format for exchanging data between a server and web applications. It can be used in many ways for mobile and web development.

I will share an example here which will demonstrate how to convert JSON string into JSON object.

Here’s how I write code.

var jsonString = '[{'
	 +		'"id" : "EMP001",'
     +		'"name" : "James Code",'
     +		'"age"  : 25,'
     +		'"departmentname" : "Android"'
     +'},'
	 +'{'
	 +		'"id" : "EMP002",'
     +		'"name" : "Rohit Sharma",'
     +		'"age"  : 32,'
     +		'"departmentname" : ".NET"'
     +'},'
	 +'{'
	 +		'"id" : "EMP003",'
     +		'"name" : "Oggy",'
     +		'"age"  : 41,'
     +		'"departmentname" : "IOS"'
     +'}]';
		
	JSON.parse(jsonString);

Run above javascript code in direct console and you can see the output as below

(3) [{…}, {…}, {…}]
0: {id: "EMP001", name: "James Code", age: 25, departmentname: "Android"}
1: {id: "EMP002", name: "Rohit Sharma", age: 32, departmentname: ".NET"}
2: {id: "EMP003", name: "Oggy", age: 41, departmentname: "IOS"}
length: 3
__proto__: Array(0)

Now you can use the JSON data for various purpose, like loop through all the element and display on the page, you can do some calculation also on that data before displaying on the page etc.

If you want to iterate through all the element in JSON object then see the below for loop example.

for (loop = 0; loop < jsonObject.length; loop++) {
console.log(jsonObject[loop].id);
console.log(jsonObject[loop].name);
}

Make sure that entered string must be in a correct JSON format or else it will give an error

That’s it. Thanks for reading my article.

152 total views, 1 views today

The “Csc” task could not be initialized with its input parameters.

In our previous post we have seen ‘How to Reset Environment Settings in Visual Studio 2017?‘, in this post we will see how to resolve an error for .NET Core compilation error.

Today I have created a new .NET Core web project using Visual Studio 2017 and faced an issue with below two errors

– MSB4063: the “Csc” task could not be initialized with its input parameters.

– MSB4064: The “SharedCompilationId” parameter is not supported by the “Csc” task. Verify the parameter exists on the task, and it is the settable public instance property

 

 

Above both errors were showing from file Microsoft.NET.Sdk.Razor.targets which is auto generated

After investigating it deeply I found that it was the existing of the razor code that causes the compilation issue. So I have searched for a issue and found that other people are also found the same issue in the release of new .NET core SDK.

I updated .NET core native SDK but it didn’t work.

After that one of my office colleague suggest me to install compiler library as NuGet package and I have installed “Microsoft.Net.Compilers” into the web project and finally error gone.

 

So if you are facing any issue like above error related to MSB4063 or MSB4064 just add the NuGet package for it.

Hope it may help someone.

434 total views, 1 views today

How to Reset Environment Settings in Visual Studio 2017?

In our previous post we have seen ‘How to get file extension using JavaScript and jQuery‘, in this post we will see how to reset environment setting in Visual Studio.

Sometimes we have set environment setting in Visual Studio 2017 and now we want to reset it then follow the below steps.

1. Open Visual Studio 2017.
2. From the Menu Bar, select Tools as like below image.

3. Now click on ‘Import and Export Settings…’ it will show dialog box as like below image.

 

4. In the opened dialog box you can see two radio button as shown in below screen. Now click on second option button ‘No, just reset settings, overwriting my current settings.’ and click Next button it will close current dialog box and open new dialog box as shown in below image.

 

5. Now select general option from the left hand box and click on Finish button it will reset all the settings you have done after installing Visual Studio and show success message as shown in below image.

 

6. Click on the Close button to close the Wizard.

That’s it.

294 total views, 1 views today