Skip to content

Commit a01488a

Browse files
author
Keanan Koppenhaver
committed
Checkpoint: Debug.log(headline), script can store parsed JSON into a variable
1 parent 0fd7d82 commit a01488a

File tree

6 files changed

+1389
-146
lines changed

6 files changed

+1389
-146
lines changed

Article.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using UnityEngine.Networking;
5+
using System.Linq;
6+
using System.Linq.Expressions;
7+
using System.Net;
8+
using System.IO;
9+
using SimpleJSON;
10+
11+
public class Article : MonoBehaviour {
12+
13+
// Use this for initialization
14+
void Start () {
15+
string headline = GetTopArticle();
16+
}
17+
18+
// Update is called once per frame
19+
void Update () {
20+
21+
}
22+
23+
private string GetTopArticle() {
24+
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://dailyprophet.alphaparticle.com/wp-json/wp/v2/posts?per_page=1");
25+
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
26+
StreamReader reader = new StreamReader(response.GetResponseStream());
27+
string jsonResponse = reader.ReadToEnd();
28+
29+
var article = JSON.Parse(jsonResponse);
30+
string headline = article[0]["title"]["rendered"].Value;
31+
32+
Debug.Log(headline);
33+
34+
return headline;
35+
}
36+
}

Articles.cs.meta renamed to Article.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Articles.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.

Helpers.cs

Lines changed: 0 additions & 128 deletions
This file was deleted.

0 commit comments

Comments
 (0)