How to serialize JSON object array with 2 or more items in vb.net -
i'm having trouble creating json object dimensional array.
see code i'm using, , if can, please me
output string json object:
{ "title":"the title", "subtitle":"some subtitle here", "category_id":"your category", "price":10, "currency_id":"real", "available_quantity":1, "buying_mode":"buy_it_now", "listing_type_id":"bronze", "condition":"new", "description": "description", "video_id": "youtube_id_here", "warranty": "12 months", "pictures":[ {"source":"http://www.yourimage/1.jpg"}, {"source":"http://www.yourimage/2.jpg"}, {"source":"http://www.yourimage/3.jpg"} ] }
json class:
generated http://jsonutils.com/
public class picture public property source string end class public class newitem public property title string public property subtitle string public property category_id string public property price integer public property currency_id string public property available_quantity integer public property buying_mode string public property listing_type_id string public property condition string public property description string public property video_id string public property warranty string public property pictures() picture end class
using class generate json object:
dim itempost new postitem() itempost.title = "não compre isso é apenas um teste" itempost.subtitle = "sub título" itempost.category_id = "mlb42369" itempost.price = 100 itempost.currency_id = "brl" itempost.available_quantity = 1 itempost.buying_mode = "buy_it_now" itempost.listing_type_id = "gold_special" itempost.condition = "new" itempost.description = "descrição produto" itempost.video_id = "https://www.youtube.com/watch?v=gta9hu6m0hk" itempost.warranty = "jesus cristo" **'here in trouble** itempost.pictures = new string() {"http://www.yourimage/1.jpg", ""http://www.yourimage/2.jpg""} messagebox.show(jsonconvert.serializeobject(itempost).tostring)
already tried in many ways, without success. sorry language errors, used google translator
edit:
i'm moving forward. follows code:
dim itempost new postitem() { .title = "não compre isso é apenas um teste", .category_id = "mlb42369", .price = 100, .currency_id = "brl", .available_quantity = 1, .buying_mode = "buy_it_now", .listing_type_id = "gold_special", .condition = "new", .description = "descrição produto", .video_id = "https://www.youtube.com/watch?v=gta9hu6m0hk", .warranty = "jesus cristo", .pictures = new picture() { .source = "" } }
messagebox.show(jsonconvert.serializeobject(itempost, formatting.indented))
follows output json:
{ "title": "não compre isso é apenas um teste", "category_id": "mlb42369", "price": 100, "currency_id": "brl", "available_quantity": 1, "buying_mode": "buy_it_now", "listing_type_id": "gold_special", "condition": "new", "description": "descrição produto", "video_id": "https://www.youtube.com/watch?v=gta9hu6m0hk", "warranty": "jesus cristo", "pictures": { "source": "" } }
the thing missing changing syntax:
"pictures": { "source": "" }
for:
"pictures": [ { "source": "" } ]
congulations, rigth.
see how code became
class code
public class picture public property source string end class public class postitem public property title string public property category_id string public property price integer public property currency_id string public property available_quantity integer public property buying_mode string public property listing_type_id string public property condition string public property description string public property video_id string public property warranty string public property pictures list(of picture) end class
code serialization
dim itempost new postitem() { .title = "não compre isso é apenas um teste", .category_id = "mlb42369", .price = 100, .currency_id = "brl", .available_quantity = 1, .buying_mode = "buy_it_now", .listing_type_id = "gold_special", .condition = "new", .description = "descrição produto", .video_id = "https://www.youtube.com/watch?v=gta9hu6m0hk", .warranty = "jesus cristo", .pictures = new list(of picture) { new picture() { .source = "foto 1"}, new picture() { .source = "foto 2"} } }
output json string
{ "title": "não compre isso é apenas um teste", "category_id": "mlb42369", "price": 100, "currency_id": "brl", "available_quantity": 1, "buying_mode": "buy_it_now", "listing_type_id": "gold_special", "condition": "new", "description": "descrição produto", "video_id": "https://www.youtube.com/watch?v=gta9hu6m0hk", "warranty": "jesus cristo", "pictures": [ { "source": "foto 1" }, { "source": "foto 2" } ] }
Comments
Post a Comment