public static string ToJSON(this BCVideo video) { return(ToJSON(video, JSONType.Update)); }
private static string ToJSON(this BCVideo video, JSONType type) { //--Build Video in JSON -------------------------------------// StringBuilder jsonVideo = new StringBuilder(); jsonVideo.Append("{"); if (type.Equals(JSONType.Update)) { //id jsonVideo.Append("\"id\": " + video.id.ToString() + ","); } //name if (!string.IsNullOrEmpty(video.name)) { jsonVideo.Append("\"name\": \"" + video.name + "\""); } //shortDescription if (!string.IsNullOrEmpty(video.shortDescription)) { jsonVideo.Append(",\"shortDescription\": \"" + video.shortDescription + "\""); } //Tags should be a list of strings if (video.tags.Count > 0) { jsonVideo.Append(",\"tags\": ["); string append = ""; foreach (string tag in video.tags) { jsonVideo.Append(append + "\"" + tag + "\""); append = ","; } jsonVideo.Append("]"); } // Custom Fields should be a list of strings if (video.customFields.Values.Count > 0) { jsonVideo.Append(",\"customFields\": {"); string append = ""; foreach (string key in video.customFields.Values.Keys) { jsonVideo.Append(append + "\"" + key + "\": \"" + video.customFields.Values[key] + "\""); append = ","; } jsonVideo.Append("}"); } //referenceId if (!string.IsNullOrEmpty(video.referenceId)) { jsonVideo.Append(",\"referenceId\": \"" + video.referenceId + "\""); } //longDescription if (!string.IsNullOrEmpty(video.longDescription)) { jsonVideo.Append(",\"longDescription\": \"" + video.longDescription + "\""); } if (!string.IsNullOrEmpty(video.linkText)) { jsonVideo.Append(",\"linkText\": \"" + video.linkText + "\""); } if (!string.IsNullOrEmpty(video.linkURL)) { jsonVideo.Append(",\"linkURL\": \"" + video.linkURL + "\""); } if (!string.IsNullOrEmpty(video.thumbnailURL)) { jsonVideo.Append(",\"thumbnailURL\": \"" + video.thumbnailURL + "\""); } if (!string.IsNullOrEmpty(video.videoStillURL)) { jsonVideo.Append(",\"videoStillURL\": \"" + video.videoStillURL + "\""); } if (video.cuePoints.Count > 0) { jsonVideo.Append(",\"cuePoints\": " + video.cuePoints.ToJSON()); } //economics jsonVideo.Append(",\"economics\": \"" + video.economics.ToString() + "\""); // Start Date jsonVideo.Append(",\"startDate\": "); if (string.IsNullOrEmpty(video.startDate)) { jsonVideo.Append("null"); } else { jsonVideo.Append("\"" + video.startDate + "\""); } // End Date jsonVideo.Append(",\"endDate\": "); if (string.IsNullOrEmpty(video.endDate)) { jsonVideo.Append("null"); } else { jsonVideo.Append("\"" + video.endDate + "\""); } jsonVideo.Append("}"); return(jsonVideo.ToString()); }
private static string ToJSON(this BCVideo video, JSONType type) { //--Build Video in JSON -------------------------------------// Builder jsonVideo = new Builder(",", "{", "}"); //id if (type.Equals(JSONType.Update)) { jsonVideo.AppendObject("id", video.id); } //referenceId if (!string.IsNullOrEmpty(video.referenceId)) { jsonVideo.AppendField("referenceId", video.referenceId); } //name if (!string.IsNullOrEmpty(video.name)) { jsonVideo.AppendField("name", video.name); } //shortDescription if (!string.IsNullOrEmpty(video.shortDescription)) { jsonVideo.AppendField("shortDescription", video.shortDescription); } //longDescription if (!string.IsNullOrEmpty(video.longDescription)) { jsonVideo.AppendField("longDescription", video.longDescription); } //Tags should be a list of strings if (video.tags.Count > 0) { jsonVideo.AppendStringArray("tags", video.tags); } //videoStillURL if (!string.IsNullOrEmpty(video.videoStillURL)) { jsonVideo.AppendField("videoStillURL", HttpUtility.UrlEncode(video.videoStillURL)); } //thumbnailURL if (!string.IsNullOrEmpty(video.thumbnailURL)) { jsonVideo.AppendField("thumbnailURL", HttpUtility.UrlEncode(video.thumbnailURL)); } if (video.cuePoints.Count > 0) { jsonVideo.AppendObject("cuePoints", video.cuePoints.ToJSON()); } if (video.renditions.Count > 0) { jsonVideo.AppendObject("renditions", video.renditions.ToJSON()); } if (!string.IsNullOrEmpty(video.videoFullLength.url) || !string.IsNullOrEmpty(video.videoFullLength.remoteUrl)) { jsonVideo.AppendObject("videoFullLength", video.videoFullLength.ToJSON()); } if (video.customFields.Values.Count > 0) { jsonVideo.AppendDictionaryArray("customFields", video.customFields.Values); } //startdate if (video.startDate != null) { jsonVideo.AppendField("startDate", BCObject.DateToUnix(video.startDate.Value)); } //enddate if (video.endDate != null) { jsonVideo.AppendField("endDate", BCObject.DateToUnix(video.endDate.Value)); } //economics jsonVideo.AppendObject("economics", video.economics.ToString()); if (video.iosRenditions.Count > 0) { jsonVideo.AppendObject("iosRenditions", video.iosRenditions.ToJSON()); } //remoteURL if (!string.IsNullOrEmpty(video.HLSURL)) { jsonVideo.AppendField("HLSURL", HttpUtility.UrlEncode(video.HLSURL)); } //adKeys if (!string.IsNullOrEmpty(video.adKeys)) { jsonVideo.AppendField("adKeys", HttpUtility.UrlEncode(video.adKeys)); } return(jsonVideo.ToString()); }