Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added JSON Parsing sample project

  • Loading branch information...
commit 2d55feac3e7b023c7c4392b36795df76069d16bb 1 parent 471f821
@gergob authored
View
46 JsonParsing/JsonParsing.sln
@@ -0,0 +1,46 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Express 2012 for Windows 8
+Project("{262852C6-CD72-467D-83FE-5EEB1973A190}") = "JsonParsing", "JsonParsing\JsonParsing.jsproj", "{363F54F1-C1BF-4E7B-9A1E-41F6725178F7}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Debug|ARM = Debug|ARM
+ Debug|x64 = Debug|x64
+ Debug|x86 = Debug|x86
+ Release|Any CPU = Release|Any CPU
+ Release|ARM = Release|ARM
+ Release|x64 = Release|x64
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {363F54F1-C1BF-4E7B-9A1E-41F6725178F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {363F54F1-C1BF-4E7B-9A1E-41F6725178F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {363F54F1-C1BF-4E7B-9A1E-41F6725178F7}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
+ {363F54F1-C1BF-4E7B-9A1E-41F6725178F7}.Debug|ARM.ActiveCfg = Debug|ARM
+ {363F54F1-C1BF-4E7B-9A1E-41F6725178F7}.Debug|ARM.Build.0 = Debug|ARM
+ {363F54F1-C1BF-4E7B-9A1E-41F6725178F7}.Debug|ARM.Deploy.0 = Debug|ARM
+ {363F54F1-C1BF-4E7B-9A1E-41F6725178F7}.Debug|x64.ActiveCfg = Debug|x64
+ {363F54F1-C1BF-4E7B-9A1E-41F6725178F7}.Debug|x64.Build.0 = Debug|x64
+ {363F54F1-C1BF-4E7B-9A1E-41F6725178F7}.Debug|x64.Deploy.0 = Debug|x64
+ {363F54F1-C1BF-4E7B-9A1E-41F6725178F7}.Debug|x86.ActiveCfg = Debug|x86
+ {363F54F1-C1BF-4E7B-9A1E-41F6725178F7}.Debug|x86.Build.0 = Debug|x86
+ {363F54F1-C1BF-4E7B-9A1E-41F6725178F7}.Debug|x86.Deploy.0 = Debug|x86
+ {363F54F1-C1BF-4E7B-9A1E-41F6725178F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {363F54F1-C1BF-4E7B-9A1E-41F6725178F7}.Release|Any CPU.Build.0 = Release|Any CPU
+ {363F54F1-C1BF-4E7B-9A1E-41F6725178F7}.Release|Any CPU.Deploy.0 = Release|Any CPU
+ {363F54F1-C1BF-4E7B-9A1E-41F6725178F7}.Release|ARM.ActiveCfg = Release|ARM
+ {363F54F1-C1BF-4E7B-9A1E-41F6725178F7}.Release|ARM.Build.0 = Release|ARM
+ {363F54F1-C1BF-4E7B-9A1E-41F6725178F7}.Release|ARM.Deploy.0 = Release|ARM
+ {363F54F1-C1BF-4E7B-9A1E-41F6725178F7}.Release|x64.ActiveCfg = Release|x64
+ {363F54F1-C1BF-4E7B-9A1E-41F6725178F7}.Release|x64.Build.0 = Release|x64
+ {363F54F1-C1BF-4E7B-9A1E-41F6725178F7}.Release|x64.Deploy.0 = Release|x64
+ {363F54F1-C1BF-4E7B-9A1E-41F6725178F7}.Release|x86.ActiveCfg = Release|x86
+ {363F54F1-C1BF-4E7B-9A1E-41F6725178F7}.Release|x86.Build.0 = Release|x86
+ {363F54F1-C1BF-4E7B-9A1E-41F6725178F7}.Release|x86.Deploy.0 = Release|x86
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
View
82 JsonParsing/JsonParsing/JsonParsing.jsproj
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|AnyCPU">
+ <Configuration>Debug</Configuration>
+ <Platform>AnyCPU</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Debug|ARM">
+ <Configuration>Debug</Configuration>
+ <Platform>ARM</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Debug|x86">
+ <Configuration>Debug</Configuration>
+ <Platform>x86</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|AnyCPU">
+ <Configuration>Release</Configuration>
+ <Platform>AnyCPU</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|ARM">
+ <Configuration>Release</Configuration>
+ <Platform>ARM</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x86">
+ <Configuration>Release</Configuration>
+ <Platform>x86</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>363f54f1-c1bf-4e7b-9a1e-41f6725178f7</ProjectGuid>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '11.0'">
+ <VisualStudioVersion>11.0</VisualStudioVersion>
+ </PropertyGroup>
+ <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+ <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\$(WMSJSProjectDirectory)\Microsoft.VisualStudio.$(WMSJSProject).Default.props" />
+ <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\$(WMSJSProjectDirectory)\Microsoft.VisualStudio.$(WMSJSProject).props" />
+ <PropertyGroup>
+ <TargetPlatformIdentifier>Windows</TargetPlatformIdentifier>
+ <TargetPlatformVersion>8.0</TargetPlatformVersion>
+ <DefaultLanguage>en-US</DefaultLanguage>
+ <PackageCertificateKeyFile>JsonParsing_TemporaryKey.pfx</PackageCertificateKeyFile>
+ </PropertyGroup>
+ <ItemGroup>
+ <AppxManifest Include="package.appxmanifest">
+ <SubType>Designer</SubType>
+ </AppxManifest>
+ <Content Include="default.html" />
+ <Content Include="images\logo.png" />
+ <Content Include="images\smalllogo.png" />
+ <Content Include="images\splashscreen.png" />
+ <Content Include="images\storelogo.png" />
+ <Content Include="js\Animal.js" />
+ <Content Include="js\default.js" />
+ <Content Include="css\default.css" />
+ <Content Include="zoo.json" />
+ <None Include="JsonParsing_TemporaryKey.pfx" />
+ </ItemGroup>
+ <ItemGroup>
+ <SDKReference Include="Microsoft.WinJS.1.0, Version=1.0" />
+ </ItemGroup>
+ <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\$(WMSJSProjectDirectory)\Microsoft.VisualStudio.$(WMSJSProject).targets" />
+ <!-- To modify your build process, add your task inside one of the targets below then uncomment
+ that target and the DisableFastUpToDateCheck PropertyGroup.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ <PropertyGroup>
+ <DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
+ </PropertyGroup>
+ -->
+</Project>
View
BIN  JsonParsing/JsonParsing/JsonParsing_TemporaryKey.pfx
Binary file not shown
View
14 JsonParsing/JsonParsing/css/default.css
@@ -0,0 +1,14 @@
+body {
+}
+
+@media screen and (-ms-view-state: fullscreen-landscape) {
+}
+
+@media screen and (-ms-view-state: filled) {
+}
+
+@media screen and (-ms-view-state: snapped) {
+}
+
+@media screen and (-ms-view-state: fullscreen-portrait) {
+}
View
19 JsonParsing/JsonParsing/default.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8" />
+ <title>JsonParsing</title>
+
+ <!-- WinJS references -->
+ <link href="//Microsoft.WinJS.1.0/css/ui-dark.css" rel="stylesheet" />
+ <script src="//Microsoft.WinJS.1.0/js/base.js"></script>
+ <script src="//Microsoft.WinJS.1.0/js/ui.js"></script>
+ <script src="/js/Animal.js"></script>
+ <!-- JsonParsing references -->
+ <link href="/css/default.css" rel="stylesheet" />
+ <script src="/js/default.js"></script>
+</head>
+<body>
+ <p>Content goes here</p>
+</body>
+</html>
View
BIN  JsonParsing/JsonParsing/images/logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  JsonParsing/JsonParsing/images/smalllogo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  JsonParsing/JsonParsing/images/splashscreen.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  JsonParsing/JsonParsing/images/storelogo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
87 JsonParsing/JsonParsing/js/Animal.js
@@ -0,0 +1,87 @@
+/// <reference path="//Microsoft.WinJS.1.0/js/base.js" />
+/// <reference path="//Microsoft.WinJS.1.0/js/ui.js" />
+
+
+(function () {
+ "use strict";
+
+ WinJS.Namespace.define("Zoo", {
+ Animal: WinJS.Class.define(
+
+ //constructor
+ function () {
+ this._name = "";
+ this._age = "";
+ this._isHungry = false;
+ this._hoursSinceLastFeed = 0;
+ },
+
+ //methods
+ {
+ getName: function () { return this._name; },
+ setName: function (newValue) { this._name = newValue; },
+
+ getAge: function () { return this._age; },
+ setAge: function (newValue) { this._age = newValue; },
+
+ isHungry: function () { return this._isHungry; },
+
+ getHoursSinceLastFeed: function () { return this._hoursSinceLastFeed; },
+ setHoursSinceLastFeed: function (newValue) {
+ this._hoursSinceLastFeed = newValue;
+
+ if (newValue > 4) {
+ this._isHungry = true;
+ }
+ else {
+ this._isHungry = false;
+ }
+ },
+ },
+
+ //static methods
+ {
+ buildAnimal: function (model) {
+
+ var newAnimal = new Zoo.Animal();
+ if (model.hasOwnProperty("name")) {
+ newAnimal.setName(model.name);
+ }
+
+ if (model.hasOwnProperty("age")) {
+ newAnimal.setAge(model.age);
+ }
+
+ if (model.hasOwnProperty("hoursSinceLastFeed")) {
+ newAnimal.setHoursSinceLastFeed(model.hoursSinceLastFeed);
+ }
+
+ return new WinJS.Binding.as(newAnimal);
+ },
+
+ loadZoo: function (uri) {
+ //IMPORTANT TO RETURN THE PROMISE
+ return Windows.Storage.StorageFile.getFileFromApplicationUriAsync(uri).then(
+ function (file) {
+
+ return Windows.Storage.FileIO.readTextAsync(file).then(
+ function (textFromFile) {
+ var myParsedJsonData = JSON.parse(textFromFile);
+
+ //this will store all the new animals added to zoo
+ var zoo = new Array();
+
+ if (myParsedJsonData) {
+
+ myParsedJsonData.forEach(function (newObject) {
+ var newAnimal = Zoo.Animal.buildAnimal(newObject);
+ zoo.push(newAnimal);
+ });
+ }
+ return zoo;
+ });
+ });
+ }
+ })//end WinJS.Class.define
+ });
+})();
View
60 JsonParsing/JsonParsing/js/default.js
@@ -0,0 +1,60 @@
+// For an introduction to the Blank template, see the following documentation:
+// http://go.microsoft.com/fwlink/?LinkId=232509
+(function () {
+ "use strict";
+
+ WinJS.Binding.optimizeBindingReferences = true;
+
+ var app = WinJS.Application;
+ var activation = Windows.ApplicationModel.Activation;
+
+ app.onactivated = function (args) {
+ if (args.detail.kind === activation.ActivationKind.launch) {
+ if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
+ // TODO: This application has been newly launched. Initialize
+ // your application here.
+ } else {
+ // TODO: This application has been reactivated from suspension.
+ // Restore application state here.
+ }
+
+ args.setPromise(WinJS.UI.processAll().then(function() {
+
+ //build up the URL for the file added to the project
+ var url = new Windows.Foundation.Uri("ms-appx:///zoo.json");
+
+ //this will store the imported data
+ var myNewAnimals = new Array();
+
+ //invoke the static method which loads the file
+ //and creates Animal objects from json data
+ //THE METHOD RETURNS A PROMISE!!!
+ Zoo.Animal.loadZoo(url).done(
+
+ function (result) {
+ myNewAnimals = result;
+
+ myNewAnimals.forEach(function (animal) {
+ console.log("Name: " + animal.getName() + ", Age: " + animal.getAge() + ", IsHungry: " + animal.isHungry() + ", Hours since Last feed: " + animal.getHoursSinceLastFeed());
+ });
+ },
+ function (error) {
+ var messDialog = new Windows.UI.Popups.MessageDialog(error);
+ messDialog.showAsync();
+ });
+
+ }));
+ }
+ };
+
+ app.oncheckpoint = function (args) {
+ // TODO: This application is about to be suspended. Save any state
+ // that needs to persist across suspensions here. You might use the
+ // WinJS.Application.sessionState object, which is automatically
+ // saved and restored across suspension. If you need to complete an
+ // asynchronous operation before your application is suspended, call
+ // args.setPromise().
+ };
+
+ app.start();
+})();
View
48 JsonParsing/JsonParsing/package.appxmanifest
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest">
+
+ <Identity
+ Name="363f54f1-c1bf-4e7b-9a1e-41f6725178f7"
+ Version="1.0.0.0"
+ Publisher="CN=Gergo" />
+
+ <Properties>
+ <DisplayName>JsonParsing</DisplayName>
+ <PublisherDisplayName>Gergo</PublisherDisplayName>
+ <Logo>images\storelogo.png</Logo>
+ </Properties>
+
+ <Prerequisites>
+ <OSMinVersion>6.2.1</OSMinVersion>
+ <OSMaxVersionTested>6.2.1</OSMaxVersionTested>
+ </Prerequisites>
+
+ <Resources>
+ <Resource Language="x-generate" />
+ </Resources>
+
+ <Applications>
+ <Application
+ Id="App"
+ StartPage="default.html">
+
+ <VisualElements
+ DisplayName="JsonParsing"
+ Logo="images\logo.png"
+ SmallLogo="images\smalllogo.png"
+ Description="JsonParsing"
+ ForegroundText="light"
+ BackgroundColor="#464646">
+
+ <DefaultTile ShowName="allLogos" />
+ <SplashScreen Image="images\splashscreen.png" />
+
+ </VisualElements>
+ </Application>
+ </Applications>
+
+ <Capabilities>
+ <Capability Name="internetClient" />
+ </Capabilities>
+
+</Package>
View
20 JsonParsing/JsonParsing/zoo.json
@@ -0,0 +1,20 @@
+[{
+ "name" : "King",
+ "age" : 5,
+ "hoursSinceLastFeed" : 3
+},
+{
+ "name" : "Geeko",
+ "age" : 2,
+ "hoursSinceLastFeed" : 12
+},
+{
+ "name" : "Nerdy",
+ "age" : 12,
+ "hoursSinceLastFeed" : 1
+},
+{
+ "name" : "Goocy",
+ "age" : 4,
+ "hoursSinceLastFeed" : 6
+}]
Please sign in to comment.
Something went wrong with that request. Please try again.