I Want to know JSON Parsing Steps. - json

enter link description here
please parse this link and result in table view.

For Visual Studio 2010
Tools->Extention Manager---Download Nuget Package Manager
Reload Visual Studio new project
Right click on project and click on NuGet Package Manager
Search by Newtonsoft and Install Newtonsoft Msgpack
using Newtonsoft.Json.Linq;
string jsonD = #"{
'FirstName':'Mahabub',
'LastName':'Zaman'
}";
var result = JObject.Parse(jsonD);
Console.Write(result["FirstName"]);
Console.Write(result["LastName"]);
Console.ReadLine();

Related

Quartz 2.6.2 and .NET Core? - Error "Could Not Initialize DataSource"

I'm using an older version of Quartz.NET (v2.6.2) with .NET Core (or possibly .NET5). I'm getting an error when attempting to use the StdSchedulerFactory.GetScheduler. All my configuration settings are within my appsettings.json where I populate a NameValueCollection with these values and inject them into my classes with DI.
["quartz.scheduler.instanceId"] = "instance_one",
["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz",
["quartz.threadPool.threadCount"] = "5",
["quartz.jobStore.misfireThreshold"] = "60000",
["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz",
["quartz.jobStore.useProperties"] = "false",
["quartz.jobStore.dataSource"] = "default",
["quartz.jobStore.tablePrefix"] = "QRTZ_",
["quartz.dataSource.default.provider"] = "SqlServer-20",
["quartz.dataSource.default.connectionString"] = quartzConn
I am using the StdSchedulerFactory like this, where Settings.Properties is that NameValueCollection which contains all the config settings:
var factory = new StdSchedulerFactory(Settings.Properties);
var scheduler = factory.GetScheduler();
On the GetScheduler method, the error, "Could Not Initialize Datasource: default" is thrown.
The crazy thing is this code works fine in a Framework 4.x project that uses a regular web.config to supply the configuration settings. Also, when I change to use Quartz 3.X with my code above, with configurations in the appsettings.json works fine. Seems that me mixing and matching both versions is causing an issue where Quartz doesn't know how to retrieve some value?
Is there a way to manually build my scheduler and not use the factory?
Thanks!
I've had to go back to Framework 4 and Quartz 2.6 to get them to play nicely together. I can only get Quartz 3.x to work with .NET Core/5. Stepping through the source code with dotPeek, Quartz 2.6 is using ConfigurationManager to pull web.config details that don't exist in Core/5. At this point I don't remember if I tried to add my own web.config file to this project or not, but I've since moved on.

How to include the HtmlSanitazationLibrary in class file

I've installed the AntiXssLibrary nuget package which also installed the HtmlSanitizationLibrary. I can include the AntiXssLibrary with
`using System.Web.Security.AntiXss;`
then use it in my code:
`AntiXssEncoder.HtmlEncode(value, true);`
I've tried doing the same with the HtmlSanitizationLibrary but Visual Studio 2019 won't recognize the similar using statement. How do I implement/use HtmlSanitizationLibrary?
The HtmlSanitizationLibrary is tucked away in a completely different namespace even though it is installed with the same library.
using Microsoft.Security.Application;
string html_fragment = "some unsafe html containing XSS";
string safe_html = Sanitizer.GetSafeHtmlFragment(html_fragment);
See https://documentation.help/Microsoft-AntiXSS/documentation.pdf, page 162 - 165.

JObject jo = new JObject() (Windows Phone 8)

I'm looking for some information about how to work with Azure Mobile Services, in a Windows Phone Client. As we can check at this link, there's some examples about how to work with mobile services.
In my case, I want to delete an ID from my SQL database. For this, we can use the example code from MSDN Documentation:
JObject jo = new JObject();
jo.Add("Id", "37BBF396-11F0-4B39-85C8-B319C729AF6D");
await table.DeleteAsync(jo);
When i paste this code into my function, I cant compile it because JObject.
This is the error I got at JObject jo = new JObject(); line:
The type or namespace name 'JObject' could not be found (are you missing a using directive or an assembly reference?)
I just can't instance a new JObject object, but the Newtonsoft.JSON are referred in my project. So I think it should work fine, but I cant instance a JObject.
This JObject class belongs to JSON.NET library (Newtonsoft).
Here's the full namespace:
Newtonsoft.Json.Linq.JObject
If you can't compile, probably you don't have the JSON.NET library in your project. Add Newtonsoft library to your project using Nuget Package.
In your VS, open your solution, open the menu Tools -> Library package manager -> package manager console
PM> Install-Package Newtonsoft.Json
When working with Windows Azure Mobile Services and Windows Phone 8. I recommend on starting from downloading the template project right from Mobile Service dashboard.
If you want to use existing project then follow the guide from dashboard how to get started.

Json does not exist in the namespace System

In this tutorial: http://www.asp.net/web-api/videos/getting-started/custom-validation Jon uses
dynamic error = new JsonObject();
with
using System.Json;
I guess it's the JsonObject here: http://msdn.microsoft.com/en-us/library/system.json.jsonobject(v=vs.110).aspx located in:
Namespace: System.Json
Assembly: System.Runtime.Serialization (in System.Runtime.Serialization.dll)
I've added System.Runtime.Serialization a reference but still cannot find System.Json.
Am I reading the Microsoft docs wrong? (I'm using .NET 4.5)
Try this:
PM> Install-Package System.Json -Version 4.0.20126.16343
Per: http://nuget.org/packages/System.Json
It worked!
If you have questions on how to add enter nuget code, please follow the link below:
http://docs.nuget.org/docs/start-here/using-the-package-manager-console
http://www.webcosmoforums.com/asp/32551-type-namespace-name-json-does-not-exist-namespace-system-runtime-serialization.html
Most likely you are missing a reference to System.ServiceModel.Web
Make sure your application is targeting the .Net 4.5 framework in the project properties.
The System.Json objects are only available in 4.5
Edit:
Use Nuget to install system.json : 'Install-Package System.Json'
How to parse JSON without JSON.NET library?
The Json object works only from Controller class and not outside. Even if we refer System.Web.MVC outside controller, we have access only to JsonResult and not to Json as Json object is protected object of JsonResult. Please refer the below documentation which explains that,
http://msdn.microsoft.com/en-us/library/dd504936(v=vs.118).aspx
If you want to use other .Net json serializer, you can use the following:
go to manage nuget package.
search json.net.
click install.
for more details, follow - http://netfx.codeplex.com/
Using System.json will not work for .Net 4 framework. The library is deprecated.
To check it try:
Go Add reference... to project.
On .Net Tab, Search System.json, you will not find any.
That means, it is deprecated.

Microsoft Azure dll throws an exception in .NET 4.0

I have developed on EXE project(use for startup task) and use following dlls of Microsoft Azure ,
It's work very well in .Net framework 3.5 but in my case i need to use system.runtime.serialization to serialize class as json string as per following way
public static string Serialize<T>(T obj)
{
System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new
System.Runtime.Serialization.Json.DataContractJsonSerializer(obj.GetType());
MemoryStream ms = new MemoryStream();
serializer.WriteObject(ms, obj);
string retVal = Encoding.Default.GetString(ms.ToArray());
ms.Dispose();
return retVal;
}
For this i need to change framework to 4.0 but at that time i got exception from Azure dlls
like
The type initializer for 'Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' threw an exception
I think all Microsoft's dlls are with backward compatibly so what's going wrong in this matter?
I should find another way to serialize to json string?
OR
I should to change Azure's dlls to latest version?
Thanks in Advance.
If you write a console app in .NET4 and want to use the RoleEnvironment then you’ll get an error:
The type initializer for ‘Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment’ threw an exception.
To get around this, just add a “useLegacyV2RuntimeActivationPolicy” to the startup tag generated in the default app.config:
<startup useLegacyV2RuntimeActivationPolicy="true">
This is because Microsoft.WindowsAzure.ServiceRuntime.dll is a mixed mode assembly. The useLegacyV2RuntimeActivationPolicy attribute is required for referencing any mixed mode assembly, not only the Windows Azure ones.
One thing you might want to check is target framework for your .Net project in Visual Studio. By default when you create a project in VS using .Net framework, it uses ".Net Framework 4 Client Profile". Try changing it to ".Net Framework 4" and see if that helps.