I'm trying to convert an array of objects (nested) to JSON string.
Here is my JSON output:
[{
"Width": 570,
"SessionID": 2003404006158805,
"Price": "69,90",
"PageCount": 24,
"Pages": [{
"ID": 1,
"TemplateID": 0,
"PageType": "cover",
"TextContainers": [],
"ImageContainers": []
}, {
"ID": 2,
"TemplateID": 1001,
"PageType": "single",
"TextContainers": [],
"ImageContainers": []
}, {
"ID": 3,
"TemplateID": 0,
"PageType": "double",
"TextContainers": [],
"ImageContainers": [{
"Width": 570,
"IsBG": true,
"Brightness": 0,
"Contrast": 0,
"PosX": null,
"ScaleX": null,
"Height": 284,
"ID": -1,
"BlackWhite": 0,
"PosY": null,
"HasPhoto": false,
"ScaleY": null,
"PhotoID": null
}]
}, {
"ID": 4,
"TemplateID": 0,
"PageType": "double",
"TextContainers": [],
"ImageContainers": [{
"Width": 570,
"IsBG": true,
"Brightness": 0,
"Contrast": 0,
"PosX": null,
"ScaleX": null,
"Height": 284,
"ID": -1,
"BlackWhite": 0,
"PosY": null,
"HasPhoto": false,
"ScaleY": null,
"PhotoID": null
}]
}],
"ProductSubID": 0,
"Height": 620,
"ProductID": 0
}]
And when I'm trying to convert this string to XML (at server side) comes out like this:
<?xml version="1.0" encoding="UTF-8" ?>
<0>
<Width>570</Width>
<SessionID>2003404006158805</SessionID>
<Price>69,90</Price>
<PageCount>24</PageCount>
<Pages>
<ID>1</ID>
<TemplateID>0</TemplateID>
<PageType>cover</PageType>
</Pages>
<Pages>
<ID>2</ID>
<TemplateID>1001</TemplateID>
<PageType>single</PageType>
</Pages>
<Pages>
<ID>3</ID>
<TemplateID>0</TemplateID>
<PageType>double</PageType>
<ImageContainers>
<Width>570</Width>
<IsBG>true</IsBG>
<Brightness>0</Brightness>
<Contrast>0</Contrast>
<PosX />
<ScaleX />
<Height>284</Height>
<ID>-1</ID>
<BlackWhite>0</BlackWhite>
<PosY />
<HasPhoto>false</HasPhoto>
<ScaleY />
<PhotoID />
</ImageContainers>
</Pages>
<Pages>
<ID>4</ID>
<TemplateID>0</TemplateID>
<PageType>double</PageType>
<ImageContainers>
<Width>570</Width>
<IsBG>true</IsBG>
<Brightness>0</Brightness>
<Contrast>0</Contrast>
<PosX />
<ScaleX />
<Height>284</Height>
<ID>-1</ID>
<BlackWhite>0</BlackWhite>
<PosY />
<HasPhoto>false</HasPhoto>
<ScaleY />
<PhotoID />
</ImageContainers>
</Pages>
<ProductSubID>0</ProductSubID>
<Height>620</Height>
<ProductID>0</ProductID>
</0>
But I need it to be like:
<pages>
<page>
</page>
<page>
</page>
</pages>
This is my AS code to convert Object arrays into JSON
var Pages:Array = [];
var Books:Array = [];
var JBook:Object = new Object();
JBook.Width = Global.BOOK_WIDTH;
for(var i:Number = 0; i<Global.PAGES.length; i++)
{
var Page:PageVO = Global.PAGES[i] as PageVO;
var JPage:Object = new Object();
JPage.ID = Page.ID;
var ImageContainers:Array = [];
var TextContainers:Array = [];
var Template:TemplateVO = Page.ACTIVE_TEMPLATE;
for(var j:Number = 0; j<Template.IMAGE_CONTAINERS.length; j++)
{
var ImageContainer:ImageContainerVO = Template.IMAGE_CONTAINERS[j] as ImageContainerVO;
var JImageContainer:Object = new Object();
JImageContainer.ID = ImageContainer.ID;
ImageContainers.push(JImageContainer);
}
for (var m:Number = 0; m<Template.TEXT_CONTAINERS.length; m++)
{
var TextContainer:TextContainerVO = Template.TEXT_CONTAINERS[m] as TextContainerVO;
var JTextContainer:Object = new Object();
JTextContainer.ID = TextContainer.ID;
}
JPage.TextContainers = TextContainers;
JPage.ImageContainers = ImageContainers;
Pages.push(JPage);
}
var Photos:Array = [];
for(var p:Number = 0; p<Global.PHOTOS.length; p++ )
{
var Photo:PhotoVO = Global.PHOTOS[p] as PhotoVO;
var JPhoto:Object = new Object();
JPhoto.BMP = ImageUtils.BitmapToBase64(Photo.BMP.bitmapData);
JPhoto.UseCount = Photo.USE_COUNT;
JPhoto.ID = Photo.ID;
Photos.push(JPhoto);
}
//JBook.Photos = Photos;
JBook.Pages = Pages;
JSON = com.adobe.serialization.json.JSON.encode(Books);
Any idea why it's rendering JSON string like they are not in the same node (seperate node for every page item)?
Hope I've been clear. Thanks.
Probably the easiest way to convert from an AS3 object to a JSON string is to use the JSON class from as3corelib.
Example usage:
var jsonString:String = JSON.encode(myDataObject);
It is probably best not to write your own parser, as the as3corelib JSON parser has been worked on and used by many people, for quite some time.
EDIT: #dpcao mentioned that you don't even need an external library anymore, Adobe introduced a new JSON class available in FlashPlayer 11.
Example usage:
var jsonString:String = JSON.stringify(myDataObject);
Are you iterating through a native object? Or through an XML Object? Because if you're iterating an [XMLList][1] you should use length(), not length (they named it as a function to avoid name collections)
But honestly, use JSONLib, or [natively][2], with Flash Player 10.3 or above, use it natively. It mimics the javascript api, with JSON.parse and JSON.stringify respectively. This shouldn't be an issue with JSON serialization, you might have a bug either server side or client side with your serialization. I would suggest adding a serialize() function to each of your objects -- this makes it easier in the long run to maintain anyways. ie:
class PageVO {
function serialize():Object {
return {
ID: some_id,
Template_ID: some_template_id,
// add image containers here
}
}
}
This will make it easier to debug individual objects to see where the problem is coming from. As it looks, there's no reason why your code shouldn't work. However, there might be issues with the actionscript serialization class and not adding a variable node: i.e. serializing [], rather than { "name": value }. Try the native serializer and see what happens. (don't forget -swf-version=16)
Related
I'm simply trying to execute the standard example bulkImport sproc for documentDB API and I can't seem to pass it an array of objects. I always get 400 errors despite the documentation giving clear direction to send an array of objects
.. very frustrating.
Additional details: Even if I wrap the array in an object with the array under a property of 'items' and include it in my sproc it still errors out saying the same bad request, needs to be an object or JSON-serialized. When I try to do JSON.stringify(docs) before sending it fails to parse on the other side.
Bad Request: The document body must be an object or a string representing a JSON-serialized object.
bulkInsert.js:
https://github.com/Azure/azure-documentdb-js-server/blob/master/samples/stored-procedures/BulkImport.js
My Code (using documentdb-util for async):
execProc(docs, insertProc);
async function execProc(docs, insertProc){
let database = await dbUtil.database('test');
let collection = await dbUtil.collection(database, 'test');
let procInstance = await dbUtil.storedProcedure(collection, insertProc);
try{
let result = await dbUtil.executeStoredProcedure(procInstance, docs);
console.log(result);
} catch(e){
console.log(e.body)
}
}
Header
Object {Cache-Control: "no-cache", x-ms-version: "2017-11-15",
User-Agent: "win32/10.0.16299 Nodejs/v8.9.0 documentdb-nodejs-s…",
x-ms-date: "Mon, 11 Dec 2017 07:32:29 GMT",
Accept:"application/json"
authorization: myauth
Cache-Control:"no-cache"
Content-Type:"application/json"
User-Agent:"win32/10.0.16299 Nodejs/v8.9.0 documentdb-nodejs-sdk/1.14.1"
x-ms-date:"Mon, 11 Dec 2017 07:32:29 GMT"
x-ms-version:"2017-11-15"
Path
"/dbs/myDB/colls/myColl/sprocs/myBulkInsert"
Params
Array(3) [Object, Object, Object]
length:3
0:Object {id: "0001", type: "donut", name: "Cake", …}
1:Object {id: "0002", type: "donut", name: "Raised", …}
2:Object {id: "0003", type: "donut", name: "Old Fashioned", …}
[{
"id": "0001",
"type": "donut",
"name": "Cake",
"ppu": 0.55
},
{
"id": "0002",
"type": "donut",
"name": "Raised",
"ppu": 0.35
},
{
"id": "0003",
"type": "donut",
"name": "Old Fashioned",
"ppu": 0.25
}]
The "docs" must be an array of array of params, otherwise, the procedure executor will treat them as multiple params of the procedure, not a single-array-param.
the following code works when call storedProcedure to pass argument with array type.
JS:
var docs = [{'id':1},{'id':2}];
executeStoredProcedure(proc, [docs])
C#
var docs = new[] {new MyDoc{id=1, source="abc"}, new MyDoc{id=2, source="abc"}];
dynamic[] args = new dynamic[] {docs};
ExecuteStoredProcedureAsync<int>(
procLink,
new RequestOptions {PartitionKey = new PartitionKey("abc")},
args);
NOTE: you must ensure the 'docs' have the same partition key, and pass partion key in RequestionOptions
I had the same problem. I was able to get it to work by Stringify the Array and parse it in the stored procedure. I opened an issue on the github where that code originated as well. Below is what worked for me. Good luck.
---- Stringify Array
var testArr = []
for (var i = 0; i < 50; i++) {
testArr.push({
"id": "test" + i
})
}
var testArrStr = JSON.stringify(testArr)
//pass testArrStr to stored procedure and parse in stored procedure
---- Slightly altered original BulkImport
exports.storedProcedure = {
id: "bulkImportArray",
serverScript:function bulkImportArray(docs) {
var context = getContext();
var collection = context.getCollection();
var docsToCreate = JSON.parse(docs)
var count = 0;
var docsLength = docsToCreate.length;
if (docsLength == 0) {
getContext().getResponse().setBody(0);
}
var totals = ""
function insertDoc(){
var msg = " count=" + count+" docsLength=" +docsLength + " typeof docsToCreate[]=" + typeof docsToCreate+ " length =" + docsToCreate.length
if(typeof docsToCreate[count] != 'undefined' ) {
collection.createDocument(collection.getSelfLink(),
docsToCreate[count],
function (err, documentCreated) {
if (err){
// throw new Error('Error' + err.message);
getContext().getResponse().setBody(count + " : " + err);
}else{
if (count < docsLength -1) {
count++;
insertDoc();
getContext().getResponse().setBody(msg);
} else {
getContext().getResponse().setBody(msg);
}
}
});
}else{
getContext().getResponse().setBody(msg);
}
}
insertDoc()
}
}
If you want to test it in the portal Script Explorer I had to create an escaped string i.e.
var testArr = []
for(var i=200; i<250; i++){
testArr.push({"id":"test"+i})
}
var testArrStr = JSON.stringify(testArr)
console.log('"'+testArrStr.replace(/\"/g,'\\"') + '"')
I have an input XML as below:
<Options>
<Series>
<Series>
<Type>Bar</Type>
<TargetAxisIndex>1</TargetAxisIndex>
</Series>
<Series>
<Type>Line</Type>
<TargetAxisIndex>2</TargetAxisIndex>
</Series>
</Series>
<Title>Test title</Title>
</Options>
I am using JsonConvert.SerializeXmlNode() and want to have my output as below:
{"Series":
{
"0": {"Type":"Bar","TargetAxisIndex":"1"},
"1": {"Type":"Line","TargetAxisIndex":"2"}
}
"Title":"Test title"
}
Is there a way of achieving this? Basically i want the node to be serialized as index.
If you don't mind going through an intermediate projection through an anonymous class, and switching from XmlDocument to the more Linq-friendly XDocument, you'll be able to leverage the Select overload which provides the index, and then apply .ToDictionary to get the Json shape you need:
var root = XDocument.Load(pathToMyDocument)
.Root;
var myObject = new
{
Title = root.Element("Title").Value,
Series = root.Element("Series")
.Elements("Series")
.Select((node, idx) =>
new
{
Node = node,
Index = idx
})
.ToDictionary(
e => e.Index,
e => new
{
Type = e.Node.Element("Type").Value,
TargetAxisIndex = e.Node.Element("TargetAxisIndex").Value
})
};
var json = JsonConvert.SerializeObject(myObject);
Result:
{
"Title": "Test title",
"Series": {
"0": {
"Type": "Bar",
"TargetAxisIndex": "1"
},
"1": {
"Type": "Line",
"TargetAxisIndex": "2"
}
}
}
Another alternative may be to do the dictionary and indexing manipulation in XSLT, before using SerializeXmlNode, by using the position() function, although you'll need to subtract 1 - it's one based.
Free Jqgrid has actions column. colmodel:
{"hidden":false,"label":"","name":"_actions","width":72
,"align":"left","template":"actions","fixed":false,"resizable":true,
"formatoptions":{"editbutton":true,"delbutton":true,"delOptions":{"url":"Delete" }}},
{"label":"Nimetus","name":"Nimi","index":"Nimi","editoptions":{"maxlength":80,"size":80 }
It is populated from remote json data like
{"total":1,
"page":1,
"rows":[{"id":"2ARVELDUSARV", "cell":[null,"2ARVELDUSARV"]},
{"id":"ACME","cell":[null,"ACME"]},
{"id":"KAKSKOERA","cell":[null,"KAKSKOERA"]}
]
}
In cell array first column is not used.
If this column is removed, jqgrid does not render data correctly since this column presence is required as placeholder for actions column.
How to fix this so that jqgrid will accept data without first column:
{"total":1,
"page":1,
"rows":[{"id":"2ARVELDUSARV", "cell":[null,"2ARVELDUSARV"]},
{"id":"ACME","cell":["ACME"]},
{"id":"KAKSKOERA","cell":["KAKSKOERA"]}
]
}
Update
I looked for data format change as recommended in answer.
jqgrid data is created from sql select statement in ASP.NET MVC4 using code below. Web API serializes this to format for json for jqgrid automatically.
How to create result which can serialized to propertyname: value format recommended in answer ?
object GetDataForJqGrid() {
IDbConnection conn;
using (var dataReader = DataAccessBase.ExecuteReader(sql.ToString(), out conn,
CommandBehavior.CloseConnection | CommandBehavior.SingleResult,
sql.GetParameters.ToArray()))
{
var rowList = new List<GridRow>();
var pkeys = DatabasePrimaryKey();
while (dataReader.Read())
{
var pkv = new List<object>();
int offset = 1; // required for actions column
var row = new GridRow
{
id = IdHelper.EncodeId(pkv),
cell = new object[dataReader.FieldCount + offset + imageCount]
};
for (int j = 0; j < dataReader.FieldCount; j++)
row.cell[offset + j] = dataReader.GetValue(j);
rowList.Add(row);
}
return new
{
total = rowList.Count() < rows ? page : page + 1, page,
rows = rowList
};
}
public class GridRow
{
public string id;
public object[] cell;
}
The most easy way would be to chanege the format of data returned from the server to use repeatitems: false style of the data. I mean the usage of
{
"total": 1,
"page": 1,
"rows": [
{ "id": "2ARVELDUSARV", "Nimi": "2ARVELDUSARV" },
{ "id": "ACME", "Nimi": "ACME" },
{ "id": "KAKSKOERA", "Nimi": "KAKSKOERA"}
]
}
or, after adding key: true to the definition of the column Nimi
{
"total": 1,
"page": 1,
"rows": [
{ "Nimi": "2ARVELDUSARV" },
{ "Nimi": "ACME" },
{ "Nimi": "KAKSKOERA"}
]
}
instead of
{
"total": 1,
"page": 1,
"rows": [{
"id": "2ARVELDUSARV",
"cell": ["2ARVELDUSARV"]
}, {
"id": "ACME",
"cell": ["ACME"]
}, {
"id": "KAKSKOERA",
"cell": ["KAKSKOERA"]
}]
}
Alternatively one can use jsonReader: { repeatitems: false } event with your current format of data and add jsonmap: "cell.0" property to, which means getting the first element (index 0) from the array cell:
$("#list").jqGrid({
datatype: "json",
url: "andrus.json",
colModel: [
{ label: "", name: "_actions", template: "actions" },
{ label: "Nimetus", name: "Nimi", jsonmap: "cell.0" }
],
iconSet: "fontAwesome",
jsonReader: { repeatitems: false }
});
see the demo.
I personally would recommend you don't use your original format (cell with array of values) and use just the named property with additional id property (if id value is not included in the item already). If you would do use the solution with jsonmap you should be carefully with changing the order of the columns (using remapColumns) and later reloading of data. You could required to update jsonmap values after the changing the column order. Thus I repeat that I recommend you to change format of data returned from the server.
UPDATED: The Updated part of your question formulate absolutely new question which have no relation with jqGrid. It's pure C# problem. Nevertheless I try to answer, because I use C# too.
What you can do with minimal changes of your code is the following: You should add using System.Dynamic; and using System.Linq; first of all. Then you should replace the code inside of using (...) {...} to about the following
var rowList = new List<dynamic>();
while (dataReader.Read()) {
var row = new ExpandoObject() as IDictionary<string, object>;
for (int j = 0; j < dataReader.FieldCount; j++) {
if (!dataReader.IsDBNull(j)) {
row.Add(dataReader.GetName(j), dataReader.GetValue(j));
}
}
rowList.Add(row);
}
Serializing of rowList will produce the names properties. If you know the primary key of the data, then you can add id property with the corresponding value in the same way (using row.Add("id", IdHelper.EncodeId(pkv))). I don't included the part because the code which you posted is not full and pkv is currently always new List<object>(), which is wrong. If the data have composed key (multiple value set is unique) then you can make string concatenation of the keys using '_' (underscore) as the separator.
I have a flash app where in a function I have to parse a json passed like an object by some external API that I can't change.
my json look like this:
{
"prodotti": [
{
"titolo": "test",
"marca": "",
"modello": "",
"cilindrata": "",
"potenza": "",
"alimentazione": "",
"images": {
"img": [
{
"thumb": "admin/uploads/img_usato/small/qekabw95L5WH1ALf6.jpg",
"big": "admin/uploads/img_usato/big/qekabw95L5WH1ALf6.jpg"
},
{
"thumb": "admin/uploads/img_usato/small/default.jpg",
"big": "admin/uploads/img_usato/big/default.jpg"
}
]
}
},
{
"titolo": "Motore Volvo TAMD 74 C",
"marca": "VOLVO PENTA",
"modello": "TAMD 74 C",
"cilindrata": "7.283 cm3",
"potenza": "331 kW a 2600 rpm",
"alimentazione": "Gasolio",
"images": {
"img": [
{
"thumb": "admin/uploads/img_usato/small/PmQwN4t4yp7P1YCWa.jpg",
"big": "admin/uploads/img_usato/big/PmQwN4t4yp7P1YCWa.jpg"
},
{
"thumb": "admin/uploads/img_usato/small/BWkjTGcy3pDM2LKRs.jpg",
"big": "admin/uploads/img_usato/big/BWkjTGcy3pDM2LKRs.jpg"
}
]
}
}
]
}
I want to parse the images inside the object.
The API send me an object not astring or json and I have this function now:
function changeData (prodotto:Object) {
img_container.graphics.clear ();
//here I want to enter and take thumb and big of images!!!
for (var index in prodotto.images.img) {
//trace('index: ' + index);
//trace("thumb: " + index.thumb + ' big: ' + index.big);
}
descrizione.htmlText = prodotto.testo_html;
titolo.text = prodotto.titolo;
alimentazione.text = prodotto.alimentazione;
potenza.text = prodotto.potenza;
cilindrata.text = prodotto.cilindrata;
modello.text = prodotto.modello;
marca.text = prodotto.marca;
}
The function works fine but not for the for loop where I try to take the bug and thumb of my json how can I retrieve this information in this object?
Thanks
I think there is something wrong with how you are setting up the call back but since you didn't show code for the api we can't fix that, plus you stated you have no control over it.
No matter what the issue is it just does not seem correct.
I put together a function that will get all the thumbs and bigs.
You did not state otherwise.
function changeData (prodotto:Object) {
for each(var item in prodotto.prodotti){
trace('')
//trace(prodotto.testo_html);
trace(item.titolo);
trace(item.alimentazione);
trace(item.potenza);
trace(item.cilindrata);
trace(item.modello);
trace(item.marca);
for each( var imgs in item.images.img) {
trace('thumb',imgs.thumb)
trace('big',imgs.big)
}
}
}
I think you need to use a JSON parser. Use the one from this link: https://github.com/mikechambers/as3corelib
1: Add the com folder to your project directory or add it to your default class path.
2: Adapt this code to your liking. I am not sure how you're getting a literal object from the API. It really should just be a string unless you're using some sort of AMF. Regardless...
import com.adobe.serialization.json.*;
var data:String = '{"prodotti":[{"titolo":"test","marca":"","modello":"","cilindrata":"","potenza":"","alimentazione":"","images":{"img":[{"thumb":"admin/uploads/img_usato/small/qekabw95L5WH1ALf6.jpg","big":"admin/uploads/img_usato/big/qekabw95L5WH1ALf6.jpg"},{"thumb":"admin/uploads/img_usato/small/default.jpg","big":"admin/uploads/img_usato/big/default.jpg"}]}},{"titolo":"Motore Volvo TAMD 74 C","marca":"VOLVO PENTA","modello":"TAMD 74 C","cilindrata":"7.283 cm3","potenza":"331 kW a 2600 rpm","alimentazione":"Gasolio","images":{"img":[{"thumb":"admin/uploads/img_usato/small/PmQwN4t4yp7P1YCWa.jpg","big":"admin/uploads/img_usato/big/PmQwN4t4yp7P1YCWa.jpg"},{"thumb":"admin/uploads/img_usato/small/BWkjTGcy3pDM2LKRs.jpg","big":"admin/uploads/img_usato/big/BWkjTGcy3pDM2LKRs.jpg"}]}}]}';
function changeData(data)
{
img_container.graphics.clear();
var obj = JSON.decode(data);
for (var i:int = 0; i < obj.prodotti.length; i++)
{
for (var k in obj.prodotti[i].images.img)
{
trace("Thumb:",obj.prodotti[i].images.img[k].thumb);
trace("Big:",obj.prodotti[i].images.img[k].big);
}
descrizione.htmlText = obj.prodotti[i].testo_html;
titolo.text = obj.prodotti[i].titolo;
alimentazione.text = obj.prodotti[i].alimentazione;
potenza.text = obj.prodotti[i].potenza;
cilindrata.text = obj.prodotti[i].cilindrata;
modello.text = obj.prodotti[i].modello;
marca.text = obj.prodotti[i].marca;
}
}
changeData(data);
I am trying to parse a local JSON file that has been stored in the applicationDataDirectory. Im just needing to grab items from this file. Running V.2 of titanium
The JSON data structure looks like this
{
"object_name": [
{
"title": "Burrton",
"value": "Burrton",
"homeof": "Chargers",
"logo": "images/logos/BURRTON.jpg",
"colors": "#cccccc;#a9a9a9",
"links": {
"tsr": "http://www.schurzdigital.com/mfeeds/CollectionFeed.php?site=http%3A%2F%2Fwww.catchitkansas.com&collection=cik_burrton_headlines&title=cik_burrton_headlines&limit=25",
"sports": "www.schurzdigital.com/mfeeds/CollectionFeed.php?site=http%3A%2F%2Fwww.catchitkansas.com&collection=cik_burden_headlines&title=cik_burden_headlines&limit=25",
"videos": "http://www.schurzdigital.com/mfeeds/TividFeedConvert.php?site=http%3A%2F%2Fwww.catchitkansas.com&slug=e9c0b075-3230-4a45-803e-7ccb4b7f754e&title=Top%20videos&limit=25",
"photos": "http://serve.a-feed.com/service/getFeed.kickAction?feedId=1014509&as=8768",
"stats": {
"boys": {
"football": "http://stats.catchitkansas.com/report_fb-schedule_results.php?sport=15&team=763",
"basketball": "http://stats.catchitkansas.com/report_baskb-schedule_results.php?sport=26&team=2946",
"cross country": "http://stats.catchitkansas.com/report_cc-schedule_results.php?sport=13&team=764",
"golf": "http://stats.catchitkansas.com/report_golf-schedule_results.php?sport=16&team=767",
"track": "http://stats.catchitkansas.com/report_trackfield-schedule_results.php?sport=32&team=2948"
},
"girls": {
"volleyball": "http://stats.catchitkansas.com/report_vb-schedule_results.php?sport=22&team=766",
"basketball": "http://stats.catchitkansas.com/report_baskb-schedule_results.php?sport=27&team=2947",
"cross country": "http://stats.catchitkansas.com/report_cc-schedule_results.php?sport=13&team=764",
"golf": "http://stats.catchitkansas.com/report_golf-schedule_results.php?sport=17&team=768",
"track": "http://stats.catchitkansas.com/report_trackfield-schedule_results.php?sport=32&team=2948"
}
}
}
}
]
}
The Code im using to parse the file.
var fileName = 'school_select.json';
var file = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, fileName);
if (file.exists()) {
var json = file.read();
var jsonObject = JSON.parse(json);
one.text = jsonObject.object_name[0].title;
two.text = jsonObject.object_name[0].homeof;
}
I answered my own question. I used the following code.
var fileName = 'school_select.json';
var file = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, fileName);
var json, object_name, locatie, i, row, title, value, homeof, logo, colors, link;
var preParseData = (file.read().text);
var response = JSON.parse(preParseData);
Ti.API.info('title = ' + response.object_name[0].title);