SRL Archive - General

[Help] VB.NET Parsing JSON string


double codes

2013-06-16 05:46:47

Im working on the item loop-up function to my runescape helper but i can't seem to figure out how to read the string properly.

I want to parse this string for example:

[{"id":"726","name":"Rune axe","image":"http:\/\/www.sublimism.com\/misc\/idb\/img\/Axe_Rune.png","recent_high":"19800.000","recent_low":"22500.000","average":"21150.000","high_alch":"7680","history":[],"offers":[{"selling":"0","quantity":"2","price":"20000","date":"1371351736","rs_name":"mos-def-boom","contact":"PM","notes":"PM Me You come to me w330 lumby basement"},{"selling":"1","quantity":"1","price":"20000","date":"1371351548","rs_name":"z-b-a-m-f-z","contact":"PM","notes":""},{"selling":"1","quantity":"2","price":"19000","date":"1371351503","rs_name":"brotha-bigz","contact":"PM","notes":"pm anytime"},{"selling":"0","quantity":"1","price":"20000","date":"1371349673","rs_name":"prince-shaka","contact":"PM","notes":""},{"selling":"1","quantity":"6","price":"20000","date":"1371348298","rs_name":"reeenatu","contact":"PM","notes":""},{"selling":"1","quantity":"9","price":"19000","date":"1371346039","rs_name":"reeenatu","contact":"PM","notes":""},{"selling":"1","quantity":"110","price":"18000","date":"1371343865","rs_name":"kptkool","contact":"PM","notes":"pm or v west bank :)"},{"selling":"1","quantity":"100","price":"17000","date":"1371343764","rs_name":"sarmetto","contact":"PM","notes":"VWEST WORLD 362"},{"selling":"1","quantity":"99","price":"25000","date":"1371340963","rs_name":"imdickie","contact":"PM","notes":"w360, v west"},{"selling":"0","quantity":"1","price":"20000","date":"1371340547","rs_name":"qwerty-dawg","contact":"PM","notes":"pm me quick"},{"selling":"0","quantity":"1","price":"24000","date":"1371340218","rs_name":"ecsi","contact":"PM","notes":""},{"selling":"0","quantity":"25","price":"20000","date":"1371339937","rs_name":"cute-bones","contact":"PM","notes":""},{"selling":"0","quantity":"1","price":"20000","date":"1371338573","rs_name":"ecsi","contact":"PM","notes":""},{"selling":"0","quantity":"1","price":"22000","date":"1371336414","rs_name":"deathshead60","contact":"PM","notes":""},{"selling":"0","quantity":"1","price":"20000","date":"1371334379","rs_name":"raunchyolman","contact":"PM","notes":"pm v west"},{"selling":"1","quantity":"1","price":"19999","date":"1371326110","rs_name":"rival-hitman","contact":"PM","notes":"lumb 330"},{"selling":"0","quantity":"1","price":"20000","date":"1371324853","rs_name":"x-semper","contact":"PM","notes":"PM me!!"},{"selling":"0","quantity":"3","price":"25000","date":"1371324663","rs_name":"zorbel","contact":"PM","notes":"URGENT"},{"selling":"1","quantity":"10","price":"16000","date":"1371323373","rs_name":"eat-sweet","contact":"PM","notes":""},{"selling":"0","quantity":"1","price":"21500","date":"1371322725","rs_name":"amoonmonster","contact":"PM","notes":""},{"selling":"1","quantity":"67","price":"20000","date":"1371317401","rs_name":"imdickie","contact":"PM","notes":"w360, v west"},{"selling":"1","quantity":"200","price":"15000","date":"1371317168","rs_name":"lets-be-epic","contact":"PM","notes":"w359 al kharid"},{"selling":"1","quantity":"67","price":"20000","date":"1371317013","rs_name":"imdickie","contact":"PM","notes":"w360, v west"},{"selling":"1","quantity":"18","price":"16000","date":"1371316652","rs_name":"ac130-spctre","contact":"PM","notes":"W345 v west"},{"selling":"1","quantity":"4","price":"21000","date":"1371316488","rs_name":"mortalpeeps","contact":"PM","notes":""},{"selling":"1","quantity":"82","price":"20000","date":"1371314864","rs_name":"imdickie","contact":"PM","notes":"w360, v west"},{"selling":"1","quantity":"88","price":"25000","date":"1371312781","rs_name":"imdickie","contact":"PM","notes":"w360, v west"},{"selling":"1","quantity":"2","price":"25000","date":"1371312269","rs_name":"jjdtje","contact":"PM","notes":""},{"selling":"1","quantity":"89","price":"25000","date":"1371311955","rs_name":"imdickie","contact":"PM","notes":"w360, v west"},{"selling":"0","quantity":"1","price":"30000","date":"1371311947","rs_name":"newts","contact":"PM","notes":""},{"selling":"1","quantity":"1","price":"25000","date":"1371311782","rs_name":"i-trevose","contact":"PM","notes":"rune axe varrock online"},{"selling":"1","quantity":"92","price":"25000","date":"1371311075","rs_name":"imdickie","contact":"PM","notes":"w360, v west"},{"selling":"1","quantity":"5","price":"25000","date":"1371310877","rs_name":"kool012","contact":"PM","notes":""},{"selling":"1","quantity":"92","price":"25000","date":"1371310457","rs_name":"imdickie","contact":"PM","notes":"w360, v west"},{"selling":"1","quantity":"4","price":"30000","date":"1371309005","rs_name":"zanerot","contact":"PM","notes":"just pm me"},{"selling":"1","quantity":"16","price":"20000","date":"1371307579","rs_name":"kool012","contact":"PM","notes":""},{"selling":"1","quantity":"35","price":"20000","date":"1371306367","rs_name":"kool012","contact":"PM","notes":""},{"selling":"0","quantity":"300","price":"17000","date":"1371301339","rs_name":"m-baba","contact":"PM","notes":"pm me in game"},{"selling":"0","quantity":"1","price":"20000","date":"1371301180","rs_name":"blb619","contact":"PM","notes":""},{"selling":"0","quantity":"1","price":"20000","date":"1371300462","rs_name":"homittus","contact":"PM","notes":""},{"selling":"1","quantity":"11","price":"30000","date":"1371299355","rs_name":"cbow-kkmc","contact":"PM","notes":""},{"selling":"1","quantity":"4","price":"20000","date":"1371297837","rs_name":"chinnin","contact":"PM","notes":""},{"selling":"1","quantity":"4","price":"30000","date":"1371297565","rs_name":"zanerot","contact":"PM","notes":"just pm me"},{"selling":"1","quantity":"4","price":"20000","date":"1371296650","rs_name":"lord-drip","contact":"PM","notes":"your world West Varrock!"},{"selling":"1","quantity":"10","price":"25000","date":"1371295391","rs_name":"bradjw2","contact":"PM","notes":"always selling"},{"selling":"0","quantity":"1","price":"30000","date":"1371293873","rs_name":"shrimpytripz","contact":"PM","notes":""},{"selling":"0","quantity":"1","price":"20000","date":"1371293648","rs_name":"rob3d-str","contact":"PM","notes":""},{"selling":"0","quantity":"1","price":"26000","date":"1371289605","rs_name":"anivia-07","contact":"PM","notes":""},{"selling":"0","quantity":"1","price":"30000","date":"1371283783","rs_name":"gavlarrrrrrr","contact":"PM","notes":"location negotiable"},{"selling":"0","quantity":"1","price":"20000","date":"1371281568","rs_name":"iiiiiliiiill","contact":"PM","notes":"Catherby W 370"}]}]


If someone could share their experience with JSON in VB.NET that would be great.

Thanks

double codes

2013-06-18 08:13:53

Sorry for bumping but i am kinda desperate, i want to get done with the RuneScape Helper.

Brandon

2013-06-18 08:57:51

From: double codes
Sorry for bumping but i am kinda desperate, i want to get done with the RuneScape Helper.


It's fairly easy to parse that string in VB :l


Create a structure that represents the tags you want to parse:


class SomeStuff
{
public String id;
public String username;
public String success;
public Result[] Results;

public class Result
{
public String msgid;
};
}


String JSONString = ""\"id\":SomeIDHere5435353,\"username\":Brandon,\"success\":Yes,\"Results\":[{\"msgid\":\"0:1351777\"}]}";

SomeStuff SS = new JavaScriptSerializer().Deserialize<SomeStuff>(JSONString);


VB & C# are pretty close, I don't think that should give you a hard time.. I'd write you the code but I don't really wanna install Visual Studio again until it fully supports the languages I use :(

Maybe I will though.. That is if no one here can help you out.. Also see here: http://stackoverflow.com/questions/3254516/help-evaluating-this-json-string-array-in-vb-net

double codes

2013-06-18 08:59:27

From: Brandon
It's fairly easy to parse that string in VB :l


Create a structure that represents the tags you want to parse:


class SomeStuff
{
public String id;
public String username;
public String success;
public Result[] Results;

public class Result
{
public String msgid;
};
}


String JSONString = ""\"id\":SomeIDHere5435353,\"username\":Brandon,\"success\":Yes,\"Results\":[{\"msgid\":\"0:1351777\"}]}"";
SomeStuff SS = new JavaScriptSerializer().Deserialize<SomeStuff>(JSONString);


VB & C# are pretty close, I don't think that should give you a hard time.. I'd write you the code but I don't really wanna install Visual Studio again until it fully supports C++x11 :(

Maybe I will though.. That is if no one here can help you out..



Thank you so much, i will check it out now to see if i can do anything with it :).

Again, Thanks.

double codes

2013-06-18 09:09:23

I am sorry because the example didn't make me understand the syntax.

I would be extremely grateful if you could write a simple example in C# or VB.NET whatever you prefer.
Credits will be given.

(I know a bit of C#)

Thanks for your effort :o